{"id":31715012,"url":"https://github.com/linna/typed-array","last_synced_at":"2025-10-09T01:51:01.907Z","repository":{"id":21616466,"uuid":"93407083","full_name":"linna/typed-array","owner":"linna","description":"Typed arrays for php","archived":false,"fork":false,"pushed_at":"2023-02-10T20:02:56.000Z","size":384,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-02T10:53:04.696Z","etag":null,"topics":["arrayobject","performance-considerations","php","type","typedarray"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linna.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-05T13:32:19.000Z","updated_at":"2022-05-16T22:39:51.000Z","dependencies_parsed_at":"2023-02-17T23:31:03.692Z","dependency_job_id":null,"html_url":"https://github.com/linna/typed-array","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/linna/typed-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linna%2Ftyped-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linna%2Ftyped-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linna%2Ftyped-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linna%2Ftyped-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linna","download_url":"https://codeload.github.com/linna/typed-array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linna%2Ftyped-array/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000705,"owners_count":26082894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrayobject","performance-considerations","php","type","typedarray"],"created_at":"2025-10-09T01:50:24.311Z","updated_at":"2025-10-09T01:51:01.902Z","avatar_url":"https://github.com/linna.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"#\"\u003e\u003cimg src=\"logo-linna-128.png\" alt=\"Linna Logo\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"#\"\u003e\u003cimg src=\"logo-array.png\" alt=\"Linna dotenv Logo\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Tests](https://github.com/linna/typed-array/actions/workflows/tests.yml/badge.svg)](https://github.com/linna/typed-array/actions/workflows/tests.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=linna_typed-array\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=linna_typed-array)\n[![PDS Skeleton](https://img.shields.io/badge/pds-skeleton-blue.svg?style=flat)](https://github.com/php-pds/skeleton)\n[![PHP 8.1](https://img.shields.io/badge/PHP-8.1-8892BF.svg)](http://php.net)\n\n\u003c/div\u003e\n\n## About\nThis package provide typed arrays for php as extension of native [ArrayObject](http://php.net/manual/en/class.arrayobject.php).  \n\n## Requirements\nThis package require php 8.1\n\n## Installation\nWith composer:\n```\ncomposer require linna/typed-array\n```\n\n## Classes\n\n| Name                  | Native Type Handled | Description                                          |\n|-----------------------|---------------------|------------------------------------------------------|\n| `ArrayOfArrays`       | array               |                                                      |\n| `ArrayOfBooleans`     | bool                |                                                      |\n| `ArrayOfCallable`     | callable            |                                                      |\n| `ArrayOfClasses`      | any existing class  | passed as first argument in constructor as `::class` |\n| `ArrayOfFloats`       | float               |                                                      |\n| `ArrayOfIntegers`     | int                 |                                                      |\n| `ArrayOfObjects`      | object              |                                                      |\n| `ArrayOfStrings`      | string              |                                                      |\n\n\n## Usage\n```php\nuse Linna\\TypedArrayObject\\ArrayOfIntegers;\nuse Linna\\TypedArrayObject\\ArrayOfClasses;\n\n//correct, only int passed to constructor.\n$intArray = new ArrayOfIntegers([1, 2, 3, 4]);\n\n//correct, int assigned\n$intArray[] = 5;\n//throw InvalidArgumentException, string assigned, int expected.\n$intArray[] = 'a';\n\n//correct, int used\n$intArray-\u003eappend(5);\n//throw InvalidArgumentException, string used, int expected.\n$intArray-\u003eappend('a');\n\n//throw InvalidArgumentException, mixed array passed to constructor.\n$otherIntArray = new ArrayOfIntegers([1, 'a', 3, 4]);\n\n//correct, only Foo class instances passed to constructor.\n$fooArray = new ArrayOfClasses(Foo::class, [\n    new Foo(),\n    new Foo()\n]);\n\n//correct, Foo() instance assigned.\n$fooArray[] = new Foo();\n//throw InvalidArgumentException, Bar() instance assigned.\n$fooArray[] = new Bar();\n\n//correct, Foo() instance used.\n$fooArray-\u003eappend(new Foo());\n//throw InvalidArgumentException, Bar() instance used, Foo() instance expected.\n$fooArray-\u003eappend(new Bar());\n\n//throw InvalidArgumentException, mixed array of instances passed to constructor.\n$otherFooArray = new ArrayOfClasses(Foo::class, [\n    new Foo(),\n    new Bar()\n]);\n```\n\n\u003e **Note:** Allowed types are: *array*, *bool*, *callable*, *float*, *int*, *object*, *string* and all existing classes.\n\n## Performance consideration for v3.0\nCompared to previous versions of the library, this version is a bit faster because every types has it own class. Do milliseconds really matters?\n\n![Array Speed Test](array-speed-test-v3.png)\n\n## Performance consideration for v2.0\nCompared to first version of the library, this version is a bit slower because after merging `TypedObjectArray` with `TypedArray`,\nthere are more code that be executed when new instance is created and on assign operations.\n\n![Array Speed Test](array-speed-test-v2.png)\n\n## Performance consideration for v1.0\nCompared to the parent class [ArrayObject](http://php.net/manual/en/class.arrayobject.php) typed arrays are slower on writing\napproximately from 6x to 8x. The slowness is due to not native `__construct()` and not native `offsetSet()`.  \nOther operations do not have a speed difference with the native ArrayObject.\n```php\nuse Linna\\TypedArray;\n\n//slower from 6x to 8x.\n$array = new TypedArray('int', [1, 2, 3, 4]);\n$array[] = 5;\n\n//other operations, fast as native.\n//for example:\n$arrayElement = $array[0];\n$elements = $array-\u003ecount();\n```\n![Array Speed Test](array-speed-test.png)\nView the speed test script on [gist](https://gist.github.com/s3b4stian/9441af5855b795cc1569b3cdb5e7526d).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinna%2Ftyped-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinna%2Ftyped-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinna%2Ftyped-array/lists"}