| ▲ | hparadiz a day ago | |||||||||||||||||||||||||||||||
With how good PHPDoc and Phan are these days I don't really think about it anymore. You can sort of have typed array by implementing Iterator, Countable, ArrayAccess, and optionally Indexing but I assume you mean defining types of array values. | ||||||||||||||||||||||||||||||||
| ▲ | Tadpole9181 a day ago | parent | next [-] | |||||||||||||||||||||||||||||||
If I could take a tangent and talk about the infuriating implicit-casting behavior of arrays in PHP?
The static analyzer will say this is safe (sans a bleeding edge setting in PHPStan), but it will throw a type error when it runs. Because the string '1' is, despite having strict types enabled, still implicitly cast to the number 1. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | someothherguyy a day ago | parent | prev [-] | |||||||||||||||||||||||||||||||
pretty naive take, no run time guarantees, basically swinging on hope to keep your shit together. phpstan drops types on static analysis for deeply nested arrays/objects for example. or even those with many members. | ||||||||||||||||||||||||||||||||