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
Treat all possible dynamic method invocations the same way #4608
As far as I know, there are 3 ways to dynamically build a method name and invoke it. The (2) and (3) in the code example above are reported by PHPstan, whereas all three are reported in strict mode. As I think there is no semantical difference between them (I can be wrong here), I think it makes sense if PHPstan reports all of them the same way.
@@ @@
PHP 8.0 (2 errors)
==========
-10: Parameter #1 $callback of function call_user_func expects callable(): mixed, array(class@anonymous/tmp.php:3, 'abc'|'not_abc') given.-11: Trying to invoke array(class@anonymous/tmp.php:3, 'abc'|'not_abc') but it might not be a callable.+10: Parameter #1 $callback of function call_user_func expects callable(): mixed, array{class@anonymous/tmp.php:3, 'abc'|'not_abc'} given.+11: Trying to invoke array{class@anonymous/tmp.php:3, 'abc'|'not_abc'} but it might not be a callable.
PHP 7.1 – 7.4 (2 errors)
==========
-10: Parameter #1 $function of function call_user_func expects callable(): mixed, array(class@anonymous/tmp.php:3, 'abc'|'not_abc') given.-11: Trying to invoke array(class@anonymous/tmp.php:3, 'abc'|'not_abc') but it might not be a callable.+10: Parameter #1 $function of function call_user_func expects callable(): mixed, array{class@anonymous/tmp.php:3, 'abc'|'not_abc'} given.+11: Trying to invoke array{class@anonymous/tmp.php:3, 'abc'|'not_abc'} but it might not be a callable.
Full report
PHP 8.0 (2 errors)
Line
Error
10
`Parameter #1 $callback of function call_user_func expects callable(): mixed, array{class@anonymous/tmp.php:3, 'abc'
11
`Trying to invoke array{class@anonymous/tmp.php:3, 'abc'
PHP 7.1 – 7.4 (2 errors)
Line
Error
10
`Parameter #1 $function of function call_user_func expects callable(): mixed, array{class@anonymous/tmp.php:3, 'abc'
11
`Trying to invoke array{class@anonymous/tmp.php:3, 'abc'
@@ @@-PHP 8.0 (2 errors)-==========--10: Parameter #1 $callback of function call_user_func expects callable(): mixed, array(class@anonymous/tmp.php:3, 'abc'|'not_abc') given.-11: Trying to invoke array(class@anonymous/tmp.php:3, 'abc'|'not_abc') but it might not be a callable.--PHP 7.1 – 7.4 (2 errors)-==========--10: Parameter #1 $function of function call_user_func expects callable(): mixed, array(class@anonymous/tmp.php:3, 'abc'|'not_abc') given.-11: Trying to invoke array(class@anonymous/tmp.php:3, 'abc'|'not_abc') but it might not be a callable.+No errors
@@ @@-PHP 8.0 (2 errors)-==========--10: Parameter #1 $callback of function call_user_func expects callable(): mixed, array(class@anonymous/tmp.php:3, 'abc'|'not_abc') given.-11: Trying to invoke array(class@anonymous/tmp.php:3, 'abc'|'not_abc') but it might not be a callable.--PHP 7.1 – 7.4 (2 errors)-==========--10: Parameter #1 $function of function call_user_func expects callable(): mixed, array(class@anonymous/tmp.php:3, 'abc'|'not_abc') given.-11: Trying to invoke array(class@anonymous/tmp.php:3, 'abc'|'not_abc') but it might not be a callable.+ 9: Call to an undefined method class@anonymous/tmp.php:3::not_abc().
Full report
Line
Error
9
Call to an undefined method class@anonymous/tmp.php:3::not_abc().
Activity
ondrejmirtes commentedon Feb 26, 2021
A similar treatment as has been done to properties also has to be done here: phpstan/phpstan-src@265afac
phpstan-bot commentedon Oct 13, 2021
@wouterj After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 (2 errors)
PHP 7.1 – 7.4 (2 errors)
phpstan-bot commentedon Sep 2, 2022
@wouterj After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:
phpstan-bot commentedon Mar 19, 2025
@wouterj After the latest push in 2.1.x, PHPStan now reports different result with your code snippet:
Full report
Call to an undefined method class@anonymous/tmp.php:3::not_abc().Add non-regression tests for phpstan/phpstan#4608
phpstan-bot commentedon Apr 7, 2026
Closed via merging phpstan/phpstan-src#5409
github-actions commentedon May 9, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.