Deprecate using "_" as a class name by Girgias · Pull Request #15360 · php/php-src

@Girgias

@Girgias

TimWolla

@Girgias Girgias deleted the class-underscore-deprecate branch

August 12, 2024 15:10

@jrfnl

@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 ?

@Girgias

Yes, internally a class, interface, trait, and enum are all the same thing.

Added some tests: 5622def

@jrfnl

Thanks for confirming Gina!

@jrfnl jrfnl mentioned this pull request

Aug 14, 2024

@SerafimArts

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?

@iluuu1994

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.

@SerafimArts

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, '_');

@iluuu1994