You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When combining templated class-string and Generics, the concrete class is missing. #4971
/** * @template T * @template K of IFoo * @param T $v * @param class-string<K> $class * @return K<T> */functionmake2($v, string$class)
{
returnnew$class($v);
}
$obj2 = make2(1, Foo::class); // I want to type Foo<int>\PHPStan\dumpType($obj2); // Kept generic type "int", but unexpected typed as "IFoo" interface
@@ @@-50: Function make2() should return IFoo<T> but returns K of IFoo.-54: Dumped type: Foo-57: Dumped type: IFoo<int>+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40+Run PHPStan with --debug option and post the stack trace to:+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
Full report
Line
Error
-1
Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
For the record the snippet should still report an error as we would create a BarIterator<int, Foo>. I have other methods to do the cast but adding them here would add a lot of noise.
Thanks a lot to PHPStan maintainers though as this tool really improves code quality.
Activity
rohm1 commentedon May 22, 2021
Possibly the same issue? https://phpstan.org/r/89101459-ba3b-4f20-b833-fcf7124a3223
phpstan-bot commentedon Sep 23, 2021
@zonuexe After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
Full report
Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.mdphpstan-bot commentedon Feb 7, 2022
@zonuexe After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
Full report
Dumped type: FooDumped type: IFoo<int>biozshock commentedon Mar 30, 2022
@zonuexe Just solved the same issue: https://phpstan.org/r/9f25afc8-fad9-4005-b2d1-7de847cf2181
Line 31 should have a
IFoo<T>to let phpstan know what type is inside the IFooFix class-string template resolution with generic args
homersimpsons commentedon Jun 30, 2026
I think I have a similar issue with the following snippet: https://phpstan.org/r/5c4a72d8-e23a-4e4c-acc7-9db4b8c9577a. In particular this method does not seem to be correctly handled by phpstan:
For the record the snippet should still report an error as we would create a
BarIterator<int, Foo>. I have other methods to do the cast but adding them here would add a lot of noise.Thanks a lot to PHPStan maintainers though as this tool really improves code quality.