Skip to content

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

Open
Amoifr wants to merge 2 commits into
phpstan:2.3.xfrom
Amoifr:feature-15368-enum-debuginfo
Open

Amoifr wants to merge 2 commits into
phpstan:2.3.xfrom
Amoifr:feature-15368-enum-debuginfo

Conversation

@Amoifr

@Amoifr Amoifr commented Oct 5, 2026

Copy link
Copy Markdown

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.

} 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())

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

2 participants