PHPStan 2.2: Unsealed Array Shapes, Safer Array Keys, and More!
- Published on PHPStan
- Curated on
It’s been almost a year and a half since we last bumped the minor version. Although we released many improvements in the 2.1.x series, grouped together in over 55 releases, we also cooked up some bigger changes people have been asking for for a long time.
Two of them have stood out ever since array shapes were first introduced seven years ago:
- The ability to intersect an array shape with a general array:
array<string, X>&array{a: Y}- meaningarray{a: Y}plus the possibility of morestringkeys whose values areX. - The ability to intersect two distinct array shapes like
array{a: X}&array{b: Y}to produce one combined shapearray{a: X, b: Y}. The motivating use cases are composable type aliases, and modelling a function that returns its input array with an extra key added.
…