Deprecate using "_" as a class name by Girgias · Pull Request #15360 · php/php-src
Girgias
deleted the
class-underscore-deprecate
branch
@Girgias Quick question as I can't test this yet what with 3v4l being behind: is this deprecation strictly about class names ? Or about all OO names, i.e. class, interface, trait and enum ?
I presume the latter, but would like to be sure when writing the sniff for PHPCompatibility.
If the latter - would it be prudent to have some tests with the other OO structures too ?
Yes, internally a class, interface, trait, and enum are all the same thing.
Added some tests: 5622def
jrfnl
mentioned this pull request
Sorry it took so long, I just saw the PR. It seems we forgot about constants (like const _ = new Placeholder()) and defines (like define('_', fopen(__FILE__, 'rb'))).
As I understand, constants were simply forgotten? Or was it done intentionally and constants will be deprecated in 8.5?
In terms of the originally stated use-case, i.e. pattern matching, there's no need for it. Identifiers in the global context of pattern matching always refer to class names rather than constants. TBH I don't know why this deprecation was added at all, given that 1. we have already decided to switch away to * exactly to prevent it, and 2. we have realized that a wildcard may not be necessary at all, given PHP has a mixed type. Anyway, hopefully the impact is minimal.
Identifiers in the global context of pattern matching always refer to class names rather than constants
What about:
const _ = Some::class; // or define('_', Some::class);
I admit that this will also work now, given the code in the PR. But I haven't checked.
class_alias(Some::class, '_');
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