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
[Enum/Trait] Call to function method_exists() will always evaluate to false #7599
Hello. I am facing issues with enum/trait combo. In some of my enums I have defined method, which can be used by trait. However I am getting Call to function method_exists() will always evaluate to false. in trait which does not have this method defined. I don't know if this is some false-positive or my code is simply trash 😉
Code is working as expected and is very similar to the snippet provided in the issue. (trait used by several enums, checking for method existence on self::class).
This would look like a false positive: we are checking in the trait that method is defined (or not) so it is expected that not all classes using that trait will have it.
I have the same issue with a function in a trait used by some Enum with self as parameter type. That particular function relies on a method that an Enum can but must not implement, hence the test with method_exists.
Would love not having to use a phpstan force ignore to get rid of the message.
@@ @@
11: Call to function method_exists() with TestEnum::Bar|TestEnum::Foo and 'barMethod' will always evaluate to false.
-PHP 7.4 – 8.0 (3 errors)+PHP 7.1 – 8.0 (3 errors)
==========
-19: Syntax error, unexpected T_STRING on line 19-21: Syntax error, unexpected T_USE on line 21-23: Syntax error, unexpected T_CASE on line 23--PHP 7.1 – 7.3 (6 errors)-==========--11: Syntax error, unexpected T_VARIABLE, expecting ')' on line 11-13: Syntax error, unexpected ',' on line 13-15: Syntax error, unexpected ')' on line 15
19: Syntax error, unexpected T_STRING on line 19
21: Syntax error, unexpected T_USE on line 21
23: Syntax error, unexpected T_CASE on line 23
Full report
PHP 8.1 (1 error)
Line
Error
11
`Call to function method_exists() with TestEnum::Bar
@@ @@
11: Call to function method_exists() with TestEnum::Bar|TestEnum::Foo and 'barMethod' will always evaluate to false.
-PHP 7.4 – 8.0 (3 errors)+PHP 8.0 (4 errors)
==========
19: Syntax error, unexpected T_STRING on line 19
-21: Syntax error, unexpected T_USE on line 21-23: Syntax error, unexpected T_CASE on line 23+20: Syntax error, unexpected '{' on line 20+27: Syntax error, unexpected T_STRING on line 27+28: Syntax error, unexpected '{' on line 28-PHP 7.1 – 7.3 (6 errors)+PHP 7.1 – 7.4 (3 errors)
==========
-11: Syntax error, unexpected T_VARIABLE, expecting ')' on line 11-13: Syntax error, unexpected ',' on line 13-15: Syntax error, unexpected ')' on line 15
19: Syntax error, unexpected T_STRING on line 19
21: Syntax error, unexpected T_USE on line 21
23: Syntax error, unexpected T_CASE on line 23
Full report
PHP 8.1 (1 error)
Line
Error
11
`Call to function method_exists() with TestEnum::Bar
@@ @@-PHP 8.1 (1 error)+PHP 8.1 (2 errors)
==========
+11: Call to function method_exists() with SecondEnum::Baz and 'barMethod' will always evaluate to true.
11: Call to function method_exists() with TestEnum::Bar|TestEnum::Foo and 'barMethod' will always evaluate to false.
-PHP 7.4 – 8.0 (3 errors)+PHP 8.0 (4 errors)
==========
19: Syntax error, unexpected T_STRING on line 19
-21: Syntax error, unexpected T_USE on line 21-23: Syntax error, unexpected T_CASE on line 23+20: Syntax error, unexpected '{' on line 20+27: Syntax error, unexpected T_STRING on line 27+28: Syntax error, unexpected '{' on line 28-PHP 7.1 – 7.3 (6 errors)+PHP 7.1 – 7.4 (3 errors)
==========
-11: Syntax error, unexpected T_VARIABLE, expecting ')' on line 11-13: Syntax error, unexpected ',' on line 13-15: Syntax error, unexpected ')' on line 15
19: Syntax error, unexpected T_STRING on line 19
21: Syntax error, unexpected T_USE on line 21
23: Syntax error, unexpected T_CASE on line 23
Full report
PHP 8.1 (2 errors)
Line
Error
11
Call to function method_exists() with SecondEnum::Baz and 'barMethod' will always evaluate to true.
11
`Call to function method_exists() with TestEnum::Bar
Activity
vpratfr commentedon Mar 1, 2023
Hi,
Same message here. I cannot get rid of it.
Code is working as expected and is very similar to the snippet provided in the issue. (trait used by several enums, checking for method existence on self::class).
This would look like a false positive: we are checking in the trait that method is defined (or not) so it is expected that not all classes using that trait will have it.
samuelgfeller commentedon Apr 30, 2024
I have the same issue with a function in a trait used by some Enum with
selfas parameter type. That particular function relies on a method that an Enum can but must not implement, hence the test withmethod_exists.Would love not having to use a phpstan force ignore to get rid of the message.
phpstan-bot commentedon Sep 4, 2024
@Dartui After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.1 (1 error)
PHP 7.1 – 8.0 (3 errors)
Syntax error, unexpected T_STRING on line 19Syntax error, unexpected T_USE on line 21Syntax error, unexpected T_CASE on line 23phpstan-bot commentedon Sep 15, 2024
@Dartui After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.1 (1 error)
PHP 8.0 (4 errors)
Syntax error, unexpected T_STRING on line 19Syntax error, unexpected '{' on line 20Syntax error, unexpected T_STRING on line 27Syntax error, unexpected '{' on line 28PHP 7.1 – 7.4 (3 errors)
Syntax error, unexpected T_STRING on line 19Syntax error, unexpected T_USE on line 21Syntax error, unexpected T_CASE on line 23phpstan-bot commentedon Sep 24, 2024
@Dartui After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.1 (2 errors)
Call to function method_exists() with SecondEnum::Baz and 'barMethod' will always evaluate to true.PHP 8.0 (4 errors)
Syntax error, unexpected T_STRING on line 19Syntax error, unexpected '{' on line 20Syntax error, unexpected T_STRING on line 27Syntax error, unexpected '{' on line 28PHP 7.1 – 7.4 (3 errors)
Syntax error, unexpected T_STRING on line 19Syntax error, unexpected T_USE on line 21Syntax error, unexpected T_CASE on line 23kartikkapatel commentedon Jan 9, 2025
+1 Same context.
adnweedon commentedon Sep 2, 2025
As the duplicate ticket has been closed, I'll comment here as well - the same issue exists for property_exists(), for the same reasons!
https://phpstan.org/r/a6fb1d5e-d6a3-4c01-86e2-946824deaf88
Add regression tests for trait-related false positives
Regression tests
github-actions commentedon Apr 28, 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.