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
Conditionally defined classes will be evaluated regardless of the current version #13133
We encountered the problem that we extend a library class which uses typed const in its newest release. To avoid PHP issues we have a conditionally defined sub-class like in this example (stripped away the inheritance): https://phpstan.org/r/c0813fbe-6808-41e2-995b-217349960e6a
Although phpstan runs on php 8.2 it still evaluates the code that is just supposed to run on PHP 8.3 and later. This means we will get an error that cannot be ignored via baseline: Class constants with native types are supported only on PHP 8.3 and later.
PHPStan should ignore the branch that is not available in PHP 8.2 and therefore not report any error. As an alternative being able to ignore this kind of error would be a workable workaround (not prefered).
Did PHPStan help you today? Did it make you happy in any way?
the rule which emits "Class constants with native types are supported only on PHP 8.3 and later." should use $scope->getPhpVersion() instead of a DI injected PhpVersion. that way the error would not be emitted in a if (PHP_VERSION_ID >= 80300) { guarded scope.
Activity
staabm commentedon Jun 10, 2025
A similar thing was implemented for a different rule in phpstan/phpstan-src#3662 - which might be useful as inspiration for a fix
staabm commentedon Jun 10, 2025
There is even a blog post about this topic in case you are interested in the bigger picture
https://staabm.github.io/2024/11/28/phpstan-php-version-in-scope.html
Apply RemoveUnusedCodeByPhpVersionIdVisitor in RichParser
staabm commentedon Sep 21, 2026
the rule which emits "Class constants with native types are supported only on PHP 8.3 and later." should use
$scope->getPhpVersion()instead of a DI injectedPhpVersion. that way the error would not be emitted in aif (PHP_VERSION_ID >= 80300) {guarded scope.Resolve "supported only on PHP X" checks from `Scope::getPhpVersion()…
Resolve "supported only on PHP X" checks from `Scope::getPhpVersion()…
Resolve "supported only on PHP X" checks from `Scope::getPhpVersion()…
Resolve property, trait constant, arrow function `never` and attribut…
github-actions commentedon Oct 23, 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.