{"id":20790388,"url":"https://github.com/paragonie/typed-arrays","last_synced_at":"2025-05-05T20:44:43.617Z","repository":{"id":239787936,"uuid":"800681635","full_name":"paragonie/typed-arrays","owner":"paragonie","description":"Userland typed array implementation","archived":false,"fork":false,"pushed_at":"2024-05-14T21:25:05.000Z","size":6,"stargazers_count":74,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-30T23:31:33.617Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paragonie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-14T19:46:19.000Z","updated_at":"2024-10-03T03:26:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"3671e198-e232-4056-ac39-136f9972e3a3","html_url":"https://github.com/paragonie/typed-arrays","commit_stats":null,"previous_names":["paragonie/typed-arrays"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Ftyped-arrays","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Ftyped-arrays/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Ftyped-arrays/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Ftyped-arrays/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paragonie","download_url":"https://codeload.github.com/paragonie/typed-arrays/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252574023,"owners_count":21770327,"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":[],"created_at":"2024-11-17T15:34:36.693Z","updated_at":"2025-05-05T20:44:43.598Z","avatar_url":"https://github.com/paragonie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Strictly Typed Arrays in PHP 8\n\n[![Build Status](https://github.com/paragonie/typed-arrays/actions/workflows/ci.yml/badge.svg)](https://github.com/paragonie/typed-arrays/actions)\n[![Latest Stable Version](https://poser.pugx.org/paragonie/typed-arrays/v/stable)](https://packagist.org/packages/paragonie/typed-arrays)\n[![Latest Unstable Version](https://poser.pugx.org/paragonie/typed-arrays/v/unstable)](https://packagist.org/packages/paragonie/typed-arrays)\n[![License](https://poser.pugx.org/paragonie/typed-arrays/license)](https://packagist.org/packages/paragonie/typed-arrays)\n[![Downloads](https://img.shields.io/packagist/dt/paragonie/typed-arrays.svg)](https://packagist.org/packages/paragonie/typed-arrays)\n\n**Requires PHP 8.3**. This is best described through example:\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nclass Foo\n{\n    public function __construct(\n        public readonly string⟦⟧ $foo,\n        public readonly int⟦⟧ $bar\n    ) {}\n}\n\n$x = new Foo(\n    string⟦⟧('apple', 'bee'),\n    int⟦⟧(4, 5, 120000),\n);\nvar_dump($x-\u003efoo, $x-\u003ebar);\nvar_dump($x-\u003efoo[1]);\n```\n\nThis should output the following:\n\n```\nobject(string⟦⟧)#5 (2) {\n  [0]=\u003e\n  string(5) \"apple\"\n  [1]=\u003e\n  string(3) \"bee\"\n}\nobject(int⟦⟧)#6 (3) {\n  [0]=\u003e\n  int(4)\n  [1]=\u003e\n  int(5)\n  [2]=\u003e\n  int(120000)\n}\nstring(3) \"bee\"\n```\n\nIf you try to pass an incorrect type, you'll get a `TypeError`:\n\n```php\n\u003c?php\ndeclare(strict_types=1);\nrequire_once 'vendor/autoload.php';\n\nclass Foo\n{\n    public function __construct(\n        public readonly string⟦⟧ $foo\n    ) {}\n}\n\n$x = new Foo(\n    string⟦⟧('apple', 'bee', 25)\n);\nvar_dump($x-\u003efoo, $x-\u003ebar);\n```\n\nShould produce:\n\n```terminal\nFatal error: Uncaught TypeError: string⟦⟧(): Argument #3 must be of type string, int given\n```\n\n## What Is This Package Doing?\n\nWe are using Unicode characters (`⟦` and `⟧`) to create a class that implements `ArrayAccess`.\nAll arguments to these types are then strictly typed.\n\nIn effect, we have turned a class into a typed array that your IDE will not complain about.\n\n## Does It Support Multi-Level Types? e.g. `string⟦⟧⟦⟧`\n\nYou betcha.\n\n```php\n\u003c?php\ndeclare(strict_types=1);\nrequire_once 'vendor/autoload.php';\n\nclass Bar\n{\n    public function __construct(\n        public readonly string⟦⟧⟦⟧ $double,\n    ) {}\n}\n\n$test = new Bar(string⟦⟧⟦⟧(\n    string⟦⟧('test'),\n    string⟦⟧('example'),\n));\nvar_dump($test-\u003edouble);\n```\n\nThis will produce:\n\n```terminal\nobject(string⟦⟧⟦⟧)#7 (2) {\n  [0]=\u003e\n  object(string⟦⟧)#5 (1) {\n    [0]=\u003e\n    string(4) \"test\"\n  }\n  [1]=\u003e\n  object(string⟦⟧)#6 (1) {\n    [0]=\u003e\n    string(7) \"example\"\n  }\n}\n```\n\n## Does This Support Arrays of Classes?\n\nOf course!\n\n```php\n\u003c?php\ndeclare(strict_types=1);\nrequire_once 'vendor/autoload.php';\n\nclass Foo {}\n\nclass Bar\n{\n    public function __construct(\n        public readonly Foo⟦⟧ $example\n    ) {}\n}\n\n$test = new Bar(new Foo⟦⟧(new Foo));\nvar_dump($test);\n```\n\nOutput:\n\n```terminal\nobject(Bar)#2 (1) {\n  [\"example\"]=\u003e\n  object(Foo⟦⟧)#5 (1) {\n    [0]=\u003e\n    object(Foo)#6 (0) {\n    }\n  }\n}\n```\n\n### How Does This Create Types for My Classes?\n\nSee: [the autoloader](global/autoloader.php).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Ftyped-arrays","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparagonie%2Ftyped-arrays","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Ftyped-arrays/lists"}