Repository navigation
Ask Scope::getPhpVersion() instead of the injected PhpVersion in rules and expression handlers - #6984
Merged
Merged
Conversation
…s and expression handlers With a phpVersion range (or a composer.json PHP constraint), the injected PhpVersion is only the range's minimum. Rules and expression handlers now ask the scope, which knows the whole range and PHP_VERSION_ID narrowing: - Rules that report a problem (deprecations, tentative return types, invalid array keys, missing magic serialization methods, ...) report it when any version in the range is affected. - Throw points (property hooks, __toString() on string casts) are added when any version in the range may throw. - Checks that only relax an error (readonly assignment from a subclass, readonly reinitialization in __clone) need every version in the range. - MutatingScope's readonly property tracking, canWriteProperty() and the clone reinitialization follow the scope's versions too, and array unpacking keeps string keys when any version supports it. The native turbo-ext mirrors follow the same changes. Amp-Thread-ID: https://ampcode.com/threads/T-01a1b1b9-0a7d-772a-a8bb-331fd76aa9cc
SplFixedArray::setSize() has the tentative return type true only since PHP 8.4. The SOAP E2E fixture is analysed in a PHP 8.2+ range from composer.json, so its implicitly nullable parameter is now reported as deprecated in PHP 8.4; declare it explicitly nullable instead. Amp-Thread-ID: https://ampcode.com/threads/T-01a1b1b9-0a7d-772a-a8bb-331fd76aa9cc
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.
Closes phpstan/phpstan#15673
With a
phpVersionrange (or acomposer.jsonPHP constraint) the injectedPhpVersionis only the range's minimum, so e.g.method.tentativeReturnTypewas not reported for a 7.4–8.5 range. Following the dynamic return type extensions that already ask the scope, rules and expression handlers now askScope::getPhpVersion(), which knows the whole range andPHP_VERSION_IDnarrowing. NewPhpVersionsmethods back the converted checks.Semantics
!->no()): OverridingMethodRule / MethodPrototypeFinder (tentative return types), FunctionDefinitionCheck (required-after-optional, implicitly nullable), invalid array keys, BacktickRule, InvalidIncDecOperationRule, MissingMagicSerializationMethodsRule, DefineParametersRule, FilterVarRule, PropertyAssignRefRule, UnsetRule.__toString()on string casts (ImplicitToStringCallHelper).->yes()): ReadOnlyPropertyAssignRule's subclass assignment and__clonereinitialization (and the matching MutatingScope clone tracking).isReadonlyPropertyFetch()(readonly narrowing carried into closures, kept on invalidation) andcanWriteProperty()follow the scope's versions.InitializerExprTypeResolver::getArrayType()takes optional?PhpVersions(likeresolveEqualType()); ArrayHandler passes the scope's, and string keys are kept on unpacking when any version supports it (below 8.1 it is an Error).The turbo-ext mirrors follow the same changes (shared
pt_mutating_scope_php_versions_trinary()helper); now-unusedPhpVersionqueries were removed.Tests
Each converted site has a test that fails without it:
*ConfigPhpTestclasses with a version-range config (7.4–8.5, 7.3–8.5 for string casts, 8.1–8.5 for readonly), type inference asserts inScopePhpVersionRangeReturnTypeExtensionsTest, andPHP_VERSION_ID-guard cases for explicit property hooks. Full suite passes with and without the extension; turbo smoke, signature parity and side-by-side pass.Still on the injected version:
InitializerExprTypeResolver::getFunctionType()(no scope; MutatingScope overrides variadics),resolveConcatType(),AccessPropertiesCheck/AccessStaticPropertiesCheck.