Repository navigation
Conversation
When a single PHP version is analysed (a fixed `phpVersion`, or no version range from the config or composer.json), PHP_VERSION_ID is int<50207, max> and Scope::getPhpVersion() treats that as no information and answers with the analysed version. A guard like `if (PHP_VERSION_ID < 80400)` narrows the constant to int<50207, 80399>, and getPhpVersion() returned that range as is, so the version dropped to PHP 5.2.7 inside the branch. Since the "supported only on PHP X" rules read the version from the scope, a class with promoted properties in such a branch got a non-ignorable property.promotedNotSupported error with `phpVersion: 80500`. Only the upper bound of that range comes from the guard. Raise the lower bound to the analysed version, or to the guard's upper bound when the guard excludes the analysed version. Guards with a lower bound (`PHP_VERSION_ID >= 80300`) and configured version ranges are unchanged. The turbo-ext mirror gets the same change. Closes phpstan/phpstan#15425
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes phpstan/phpstan#15425. Thanks @lstrojny for the report and the reproducer.
When a single PHP version is analysed (a fixed
phpVersion, or no version range from the config or composer.json),PHP_VERSION_IDisint<50207, max>.Scope::getPhpVersion()treats that as "no information" and answers with the analysed version. A guard likeif (PHP_VERSION_ID < 80400)narrows the constant toint<50207, 80399>, andgetPhpVersion()returned that range as is, so inside the branch the version dropped to PHP 5.2.7. Since 2.3 the "supported only on PHP X" rules read the version from the scope, so withphpVersion: 80500a class with promoted properties in that branch got the non-ignorableproperty.promotedNotSupportederror. A guard the analysed version passes, likePHP_VERSION_ID < 80600, hit the same error.Only the upper bound of such a range comes from the guard.
getPhpVersion()now raises the lower bound to the analysed version, or to the guard's upper bound when the guard excludes the analysed version. WithphpVersion: 80500,PHP_VERSION_ID < 80600givesint<80500, 80599>andPHP_VERSION_ID < 80400gives80399. Guards that set a lower bound (PHP_VERSION_ID >= 80300, the bug-13133 case) and configured version ranges are unchanged. APHP_VERSION_ID < 80000branch still reports promoted properties, astestConditionallyDeclaredClassexpects. The narrowed type of thePHP_VERSION_IDconstant itself does not change.MutatingScopeis shadowed by turbo-ext, soMutatingScope.cppgets the same change and the generated header is regenerated.turbo-ext/tests/scope-family.phpgets two guarded scopes pinned tophpVersion: 80500(one where the guard excludes the analysed version, one where it doesn't). The smoke test fails on them if the native side is wrong. A separate commit bumps the expected turbo version.InvalidPromotedPropertiesRuleTest::testBug15425analyses the issue's snippet and expects no errors. Without the fix it fails withPromoted properties are supported only on PHP 8.0 and later.The full test suite passes with and without the turbo extension loaded.Closes phpstan/phpstan#15425