Bug report
After upgrading to PHPStan 2.3.0, analysis crashes with PHPStan\ShouldNotHappenException: Internal error. when a generic array argument contains both a first-class instance method callable and an anonymous function.
The exception originates in InitializerExprTypeResolver.php:743, with getFirstClassCallableType() and gatherArrayArgTypeSkeleton() in the stack trace.
I reproduced this without Laravel, Larastan, or other extensions, using PHP 8.5.11 at analysis level 8. The same code passes analysis with PHPStan 2.2.17 and executes successfully in PHP.
Assigning the method callable to a variable before placing it in the array avoids the crash in PHPStan 2.3.0.
Code snippet that reproduces the problem
https://phpstan.org/r/3ad3115b-59c2-46e6-b10c-5443aa613e71
Expected output
PHPStan should complete analysis without errors, as PHPStan 2.2.17 does for the same snippet. Both callbacks satisfy the declared parameter type, and the code executes successfully in PHP.
PHPStan 2.3.0 should produce the same result whether the method callable is placed directly in the array or assigned to a variable first. Neither form should cause an internal error.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan regularly catches issues before they reach production and gives me more confidence when refactoring. Thanks for all the work you put into it!
Bug report
After upgrading to PHPStan 2.3.0, analysis crashes with PHPStan\ShouldNotHappenException: Internal error. when a generic array argument contains both a first-class instance method callable and an anonymous function.
The exception originates in InitializerExprTypeResolver.php:743, with getFirstClassCallableType() and gatherArrayArgTypeSkeleton() in the stack trace.
I reproduced this without Laravel, Larastan, or other extensions, using PHP 8.5.11 at analysis level 8. The same code passes analysis with PHPStan 2.2.17 and executes successfully in PHP.
Assigning the method callable to a variable before placing it in the array avoids the crash in PHPStan 2.3.0.
Code snippet that reproduces the problem
https://phpstan.org/r/3ad3115b-59c2-46e6-b10c-5443aa613e71
Expected output
PHPStan should complete analysis without errors, as PHPStan 2.2.17 does for the same snippet. Both callbacks satisfy the declared parameter type, and the code executes successfully in PHP.
PHPStan 2.3.0 should produce the same result whether the method callable is placed directly in the array or assigned to a variable first. Neither form should cause an internal error.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan regularly catches issues before they reach production and gives me more confidence when refactoring. Thanks for all the work you put into it!