Skip to content

Commit 69da612

Browse files
authored
README.md updated
1 parent 4590d72 commit 69da612

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Code Coverage](https://scrutinizer-ci.com/g/s3b4stian/linna-array/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/s3b4stian/linna-array/?branch=master)
88
[![StyleCI](https://styleci.io/repos/93407083/shield?branch=master&style=flat)](https://styleci.io/repos/93407083)
99

10-
## Typed arrays for php
10+
# Typed arrays for php
1111
Provide typed arrays for php as extension of native [ArrayObject](http://php.net/manual/en/class.arrayobject.php)
1212

1313
## Requirements
@@ -19,36 +19,46 @@ With composer:
1919
composer require s3b4stian/linna-array
2020
```
2121

22-
## Usage
23-
Valid for intArray, stringArray and floatArray classes
22+
## Usage TypedArray
2423
```php
25-
use Linna\intArray;
24+
use Linna\TypedArray;
2625

27-
//int array
2826
//correct, only int passed to array.
29-
$intArray = new intArray([1, 2, 3, 4]);
30-
$intArray[] = 5;
27+
$array = new TypedArray('int', [1, 2, 3, 4]);
28+
$array[] = 5;
3129

32-
//throw TypeError.
33-
$intArray = new intArray([1, 'a', 3, 4]);
34-
$intArray[] = 'a';
30+
//throw InvalidArgumentException.
31+
$array = new TypedArray([1, 'a', 3, 4]);
32+
$array[] = 'a';
33+
```
34+
Allowed types are: array, bool, callable, float, int, object, string.
35+
```php
36+
use Linna\TypedArray;
37+
38+
$intArray = new TypedArray('int');
39+
$arrayArray = new TypedArray('array');
40+
$boolArray = new TypedArray('bool');
41+
$callableArray = new TypedArray('callable');
42+
$floatArray = new TypedArray('float');
43+
$intArray = new TypedArray('int');
44+
$objectArray = new TypedArray('object');
45+
$stringArray = new TypedArray('string');
3546
```
3647

37-
### Performance consideration
48+
## Performance consideration
3849
Compared to the parent class [ArrayObject](http://php.net/manual/en/class.arrayobject.php) typed arrays are slower on writing
3950
approximately from 15x to 20x. The slowness is due to not native `__construct()` and not native `offsetSet()`.
4051
Other operations do not have a speed difference with the native ArrayObject.
4152
```php
42-
use Linna\intArray;
53+
use Linna\TypedArray;
4354

4455
//slower from 15x to 20x.
45-
$intArray = new intArray([1, 2, 3, 4]);
46-
$intArray[] = 5;
56+
$array = new TypedArray('int', [1, 2, 3, 4]);
57+
$array[] = 5;
4758

4859
//other operations, fast as native.
4960
//for example:
50-
$arrayElement = $intArray[0];
51-
$elements = $intArray->count();
52-
$array = (array) $intArray;
61+
$arrayElement = $array[0];
62+
$elements = $array->count();
5363
```
5464

0 commit comments

Comments
 (0)