Skip to content

Native types of class constants and tentative return types, walk dead catches and closure attributes - #6859

Merged
ondrejmirtes merged 4 commits into
2.3.xfrom
native-types-dead-catch-closure-attributes
Oct 27, 2026
Merged

ondrejmirtes merged 4 commits into
2.3.xfrom
native-types-dead-catch-closure-attributes

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Four fixes found while auditing where Rector works around PHPStan behaviour.

Native type of class constant fetches ignored @var. getNativeType() of static::FOO on a non-final class returned the @var PHPDoc type, so with treatPhpDocTypesAsCertain: false comparisons like static::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 to mixed without 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()) was mixed. On PHP 8.1+ the tentative return type is now the native return type when the signature has none. Before PHP 8.1, OverridingMethodRule no longer reports return types that are only tentative (previously this relied on the native type being mixed).

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-14397 and testBug4043 expectations changed accordingly (the catch body is now analysed, so $foo is maybe-defined there, and a treatPhpDocTypesAsCertain tip is no longer shown).

Attributes of closures and arrow functions are walked through AttributesHandler, like those of functions and methods, so rules such as ClassConstantRule see their arguments.

All four have the matching turbo-ext changes. Tests pass with and without the extension; make phpstan and make cs are clean; side-by-side.php, signature-parity.php and smoke.php pass.

@ondrejmirtes
ondrejmirtes force-pushed the native-types-dead-catch-closure-attributes branch 2 times, most recently from 17db8d0 to 4829cef Compare October 27, 2026 07:17
@ondrejmirtes
ondrejmirtes force-pushed the native-types-dead-catch-closure-attributes branch from 4829cef to 62b757b Compare October 27, 2026 08:40
@ondrejmirtes
ondrejmirtes merged commit b06df46 into 2.3.x Oct 27, 2026
545 of 546 checks passed
@ondrejmirtes
ondrejmirtes deleted the native-types-dead-catch-closure-attributes branch October 27, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant