-
-
Notifications
You must be signed in to change notification settings - Fork 938
Description
Bug report
I was trying to use a @param phpdoc with an array shape to typecheck my array input. This worked with small arrays, but as I'm generating PHP code I have very large array shapes. The generated code does an array_key_exists because many of my keys have optional values. PHPStan incorrectly gives an error when trying to use values from the input array as the type it should be.
Curiously, the first time the type is correct but then due to type narrowing it becomes incorrect.
The code snippet shows a minimal reproducer.
I asked claude code to debug this problem for me in PHPStan. If you're interested I also have the solution claude found. I am totally unfamiliar with the codebase, which is why I'm not making a PR with AI generated code as I would consider that rude. But I did find it really interesting that claude came up with a very small fix (and a nice test case): pingiun/phpstan-src@19816a4
Code snippet that reproduces the problem
https://phpstan.org/r/46da7941-d28f-4b02-8291-920714e8143b
Expected output
35 | Dumped type: float
41 | Dumped type: float
Did PHPStan help you today? Did it make you happy in any way?
I'm a happy user of PHPStan and was inspired by Nuno Maduro to set phpstan to max!