PHP port of JavaScript's Array API with TypeScript-style generics. Keep behavior close to JavaScript Array; the test suite is the spec.
src/Arr.phpis the main implementation.tests/Unit/ArrTest.phpis the main spec and is organized by JS API section order.tests/Integration/DocumentationExamplesTest.phpverifies the PHP examples inREADME.mdanddoc/Arr.md.- Update
doc/Arr.mdandREADME.mdwhen public behavior changes.
- Keep
declare(strict_types=1);, typed properties,finalclasses, and the detailed PHPDoc generics/callable signatures inArr. - Method ordering rule for
Arr.php: (1) magic methods__*; (2) interface methods, in the order listed inimplements; (3) the rest sorted by MDN JSArrayorder (statics first, then instance methods); (4) non-JS methods at the end. Mirror that order intests/Unit/ArrTest.php,doc/Arr.md, andtests/Integration/DocumentationExamplesTest.php. thisArgsupport is intentional: bind only non-staticClosurecallables; other callables ignore it.
- Preserve sparse-array semantics.
lengthmay be greater than the number of populated indexes. - Holes read back as
nullthroughat(),values(),toArray(), andjsonSerialize(), butoffsetExists()/isset()must still distinguish between missing indexes and explicitnullvalues. - Favor JavaScript
Arraysemantics over idiomatic PHP shortcuts.
- Use Composer scripts as the default workflow:
composer test:unit,composer test:integration,composer test:static-analysis,composer test:cs, orcomposer test. - PHPUnit runs in random order, so avoid hidden test coupling.
- Keep every PHP example in
README.mdanddoc/Arr.mdexecutable and in sync withtests/Integration/DocumentationExamplesTest.php; add one integration test per documented example block.