: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:

Related to #1849