Repository navigation
Native types of class constants and tentative return types, walk dead catches and closure attributes - #6859
Merged
Conversation
ondrejmirtes
force-pushed
the
native-types-dead-catch-closure-attributes
branch
2 times, most recently
from
October 27, 2026 07:17
17db8d0 to
4829cef
Compare
ondrejmirtes
force-pushed
the
native-types-dead-catch-closure-attributes
branch
from
October 27, 2026 08:40
4829cef to
62b757b
Compare
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.
Four fixes found while auditing where Rector works around PHPStan behaviour.
Native type of class constant fetches ignored
@var.getNativeType()ofstatic::FOOon a non-final class returned the@varPHPDoc type, so withtreatPhpDocTypesAsCertain: falsecomparisons likestatic::FOO === ''were reported as always false. With native types promoted, the PHPDoc type is no longer used: an overridable constant resolves to its native type, or tomixedwithout one. Final constants and constants of final classes still resolve to their value.Tentative return types of built-in methods are native return types.
getNativeType($arrayObject->count())wasmixed. On PHP 8.1+ the tentative return type is now the native return type when the signature has none. Before PHP 8.1,OverridingMethodRuleno longer reports return types that are only tentative (previously this relied on the native type beingmixed).Dead catch blocks are walked. When no throw point matched a catch, its statements were never analysed, so
catch (\InvalidArgumentException $e) { $e->nonExistent(); }after a try that cannot throw only reported "Dead catch". The body is now walked with the declared catch type; the result does not flow into the rest of the function.bug-14397andtestBug4043expectations changed accordingly (the catch body is now analysed, so$foois maybe-defined there, and atreatPhpDocTypesAsCertaintip is no longer shown).Attributes of closures and arrow functions are walked through
AttributesHandler, like those of functions and methods, so rules such asClassConstantRulesee their arguments.All four have the matching turbo-ext changes. Tests pass with and without the extension;
make phpstanandmake csare clean;side-by-side.php,signature-parity.phpandsmoke.phppass.