:sparkles: New `PHPCompatibility.Keywords.ForbiddenClassAlias` sniff by jrfnl · Pull Request #1952 · PHPCompatibility/PHPCompatibility
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
- Fix GH-16665: \array and \callable should not be usable php/php-src#16683
- php/php-src@96d1cd0
Related to #1849