{"id":22793186,"url":"https://github.com/ngmy/php-typed-array","last_synced_at":"2025-07-26T21:38:02.647Z","repository":{"id":51703718,"uuid":"339093750","full_name":"ngmy/php-typed-array","owner":"ngmy","description":"The typed array for PHP","archived":false,"fork":false,"pushed_at":"2021-05-10T16:35:05.000Z","size":228,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T20:04:24.363Z","etag":null,"topics":["array","library","php","php-library","type","typed-array"],"latest_commit_sha":null,"homepage":"","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/ngmy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"ngmy","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://flattr.com/@ngmy"}},"created_at":"2021-02-15T13:54:46.000Z","updated_at":"2024-01-08T17:00:09.000Z","dependencies_parsed_at":"2022-08-03T08:30:49.402Z","dependency_job_id":null,"html_url":"https://github.com/ngmy/php-typed-array","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-typed-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-typed-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-typed-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-typed-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngmy","download_url":"https://codeload.github.com/ngmy/php-typed-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246351393,"owners_count":20763293,"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","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":["array","library","php","php-library","type","typed-array"],"created_at":"2024-12-12T03:18:28.102Z","updated_at":"2025-03-30T17:20:50.624Z","avatar_url":"https://github.com/ngmy.png","language":"PHP","funding_links":["https://github.com/sponsors/ngmy","https://flattr.com/@ngmy"],"categories":[],"sub_categories":[],"readme":"# PHP Typed Array\n[![Latest Stable Version](https://poser.pugx.org/ngmy/typed-array/v)](//packagist.org/packages/ngmy/typed-array)\n[![Total Downloads](https://poser.pugx.org/ngmy/typed-array/downloads)](//packagist.org/packages/ngmy/typed-array)\n[![Latest Unstable Version](https://poser.pugx.org/ngmy/typed-array/v/unstable)](//packagist.org/packages/ngmy/typed-array)\n[![License](https://poser.pugx.org/ngmy/typed-array/license)](//packagist.org/packages/ngmy/typed-array)\n[![composer.lock](https://poser.pugx.org/ngmy/typed-array/composerlock)](//packagist.org/packages/ngmy/typed-array)\n[![PHP CI](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml/badge.svg)](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml)\n[![Coverage Status](https://coveralls.io/repos/github/ngmy/php-typed-array/badge.svg?branch=master)](https://coveralls.io/github/ngmy/php-typed-array?branch=master)\n[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)\n[![Psalm Coverage](https://shepherd.dev/github/ngmy/php-typed-array/coverage.svg?)](https://shepherd.dev/github/ngmy/php-typed-array)\n[![Psalm Level](https://shepherd.dev/github/ngmy/php-typed-array/level.svg?)](https://shepherd.dev/github/ngmy/php-typed-array)\n\nPHP Typed Array is the typed array for PHP.\n\n- Can create the typed array with the specified key and value type\n- Can specify the bool, float, int, object, resource, or string type, or the specified class type, or the class type that implements the specified interface, or the class type that uses the specified trait for the key type\n- Can specify the array, bool, float, int, object, resource, or string type, or the specified class type, or the class type that implements the specified interface, or the class type that uses the specified trait for the value type\n- Implements the `ArrayAccess`, `Countable`, and `IteratorAggregate` interfaces\n- Supports the static analysis like PHPStan and Psalm. Please see [examples](docs/examples)\n\n```php\n// Returns a new instance of the typed array with the int type value\n$intArray = Ngmy\\TypedArray\\TypedArray::new()-\u003ewithIntValue(); // TypedArray\u003cmixed, int\u003e\n\n$intArray[] = 1;      // Good\n// $intArray[] = '2'; // No good. The InvalidArgumentException exception is thrown\n\n// Returns a new instance of the typed array with the class type value that implements the DateTimeInterface interface\n$dateTimeInterfaceArray = Ngmy\\TypedArray\\TypedArray::new()\n    -\u003ewithInterfaceValue(DateTimeInterface::class); // TypedArray\u003cmixed, DateTimeInterface\u003e\n\n$dateTimeInterfaceArray[] = new DateTime();          // Good\n$dateTimeInterfaceArray[] = new DateTimeImmutable(); // Good\n// $dateTimeInterfaceArray[] = new stdClass();       // No good. The InvalidArgumentException exception is thrown\n\nforeach ($dateTimeInterfaceArray as $dateTime) {\n    echo $dateTime-\u003eformat('Y-m-d H:i:s') . PHP_EOL;\n}\n\n// Determines if the typed array is empty or not\necho var_export($dateTimeInterfaceArray-\u003eisEmpty(), true) . PHP_EOL; // false\n\n// Gets the typed array of items as a plain array\nprint_r($dateTimeInterfaceArray-\u003etoArray());\n// Array\n// (\n//     [0] =\u003e DateTime Object\n//         ...\n//     [1] =\u003e DateTimeImmutable Object\n//         ...\n// )\n\n// You can also specify the type of the key\n$stringKeyArray = Ngmy\\TypedArray\\TypedArray::new()-\u003ewithStringKey(); // TypedArray\u003cstring, mixed\u003e\n$stringKeyArray['foo'] = 1; // Good\n// $stringKeyArray[] = 2;   // No good. The InvalidArgumentException exception is thrown\n\n// Of course, you can also specify the type of both the key and the value\n$intStringArray = Ngmy\\TypedArray\\TypedArray::new()-\u003ewithIntKey()-\u003ewithStringValue(); // TypedArray\u003cint, string\u003e\n```\n\n## Requirements\nPHP Typed Array has the following requirements:\n\n* PHP \u003e= 7.3\n\n## Installation\nExecute the Composer `require` command:\n```console\ncomposer require ngmy/typed-array\n```\n\n## Documentation\nPlease see the [API documentation](https://ngmy.github.io/php-typed-array/api/).\n\n## License\nPHP Typed Array is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngmy%2Fphp-typed-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngmy%2Fphp-typed-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngmy%2Fphp-typed-array/lists"}