✨ New PHPCompatibility.Keywords.ForbiddenClassAlias sniff#1952
Merged
Conversation
Inspired by the following change in PHP 8.5: > - Core: > . It is no longer possible to use "array" and "callable" as class alias names > in class_alias(). ... I've done a deep-dive into type keywords versus the `class_alias()` function. Turns out "normal" reserved keywords are allowed as class aliases: https://3v4l.org/jMsDd Don't ask me why, as using these aliases would be complicated as "normal" usages like `new Name()` would be a parse error, but that's not our concern. It's not forbidden by PHP itself. However, the "other" reserved keywords _are_ forbidden as class alias names since PHP 7.0, with new type keywords which were added in later PHP versions being forbidden as of that PHP version. https://3v4l.org/9Knt7 That is, with the exception of `array` and `callable`, which were forgotten in PHP 7.0, with that oversight being fixed now in PHP 8.5. https://3v4l.org/P0sii#veol https://3v4l.org/P0sii#vgit.master This commit introduces a new sniff which detects calls to the `class_alias()` function with any of these forbidden names as the alias. Includes tests. Includes documentation. Ref: * https://github.com/php/php-src/blob/18687e4f394f7efb1fc84ad5a7a6721f2774a764/UPGRADING#L22-L24 * https://github.com/php/php-src/blob/9b23fb29aba3bcd5ae5aee116fc35b103902a9fa/Zend/zend_compile.c#L202-L223 * Original commit from PHP 7.0: php/php-src@53a4038 * php/php-src 16683 * php/php-src@96d1cd0 Related to 1849
wimg
approved these changes
Oct 27, 2025
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.
Inspired by the following change in PHP 8.5:
... I've done a deep-dive into type keywords versus the
class_alias()function.Turns out "normal" reserved keywords are allowed as class aliases: https://3v4l.org/jMsDd
Don't ask me why, as using these aliases would be complicated as "normal" usages like
new Name()would be a parse error, but that's not our concern. It's not forbidden by PHP itself.However, the "other" reserved keywords are forbidden as class alias names since PHP 7.0, with new type keywords which were added in later PHP versions being forbidden as of that PHP version. https://3v4l.org/9Knt7
That is, with the exception of
arrayandcallable, which were forgotten in PHP 7.0, with that oversight being fixed now in PHP 8.5.https://3v4l.org/P0sii#veol
https://3v4l.org/P0sii#vgit.master
This commit introduces a new sniff which detects calls to the
class_alias()function with any of these forbidden names as the alias.Includes tests.
Includes documentation.
Ref:
Related to #1849