phpstan-src
phpstan-src copied to clipboard
ConstantArrayType: fix returned ConstantArrayTypeAndMethod
With this, we can recognize those cases:
class Parnt
{
public function __construct()
{
array_map([self::class, 'method1'], [1]); // calls Parnt::method1
array_map([$this, 'method1'], [1]); // calls Child::method1
}
public function method1(): void {
echo 'parent';
}
}
class Child extends Parnt
{
public function __construct()
{
parent::__construct();
}
public function method1(): void {
echo 'child';
}
}
new Child();
Is missing a test
I'm not sure if there is any native functionality to test against. I need this function for proper dead-code analysis.
If nothing else is possible then we need a unit test in ConstantArrayTypeTest. Make sure to initialize $this->createReflectionProvider() so that the Type works properly.
Added a test and rebased on top of 2.0.x
Thank you.
I'm sorry, had to revert this. There are regressions (could be seen in the issue bot):
- https://github.com/phpstan/phpstan/issues/11859
- https://github.com/phpstan/phpstan/issues/8071