Skip to content

Allow __debugInfo() in enums on PHP 8.6+ - #6682

Merged
ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
Amoifr:feature-15368-enum-debuginfo
Nov 15, 2026
Merged

ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
Amoifr:feature-15368-enum-debuginfo

Conversation

@Amoifr

@Amoifr Amoifr commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Closes phpstan/phpstan#15368

PHP 8.6 allows enums to implement __debugInfo() (RFC). EnumSanityRule now skips it when the scope's PHP version is 8.6 or later, through a new PhpVersions::supportsDebugInfoOnEnums(). Other magic methods are still reported.

The test follows ReadOnlyClassRuleTest::testConditionallyDeclaredClass: enums declared in PHP_VERSION_ID branches, and the expected errors depend on the PHP version running the tests.

Comment thread src/Rules/Classes/EnumSanityRule.php Outdated
} elseif (!array_key_exists($lowercasedMethodName, self::ALLOWED_MAGIC_METHODS)) {
} elseif (
!array_key_exists($lowercasedMethodName, self::ALLOWED_MAGIC_METHODS)
&& !($lowercasedMethodName === '__debuginfo' && $scope->getPhpVersion()->supportsDebugInfoOnEnums()->yes())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&& !($lowercasedMethodName === '__debuginfo' && $scope->getPhpVersion()->supportsDebugInfoOnEnums()->yes())
&& ($lowercasedMethodName !== '__debuginfo' || !$scope->getPhpVersion()->supportsDebugInfoOnEnums()->yes())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied, thanks! I also added EnumSanityRuleConfigPhpTest with a 8.5 to 8.6 version range, which kills the mutant that escaped in mutation testing. 🙂

@VincentLanglet
VincentLanglet requested a review from staabm October 6, 2026 07:42
@ondrejmirtes
ondrejmirtes force-pushed the feature-15368-enum-debuginfo branch from cb2d060 to 07cc243 Compare November 15, 2026 11:26
@ondrejmirtes
ondrejmirtes force-pushed the feature-15368-enum-debuginfo branch from 07cc243 to 59e9346 Compare November 15, 2026 11:32
@ondrejmirtes
ondrejmirtes merged commit 1a247e4 into phpstan:2.3.x Nov 15, 2026
371 of 376 checks passed
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.

Enum can implements __debugInfo since PHP 8.6

3 participants