Deprecate using "_" as a class name#15360
Conversation
|
@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 |
|
Thanks for confirming Gina! |
|
Sorry it took so long, I just saw the PR. It seems we forgot about constants (like 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 |
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, '_'); |
|
As mentioned, consts are not relevant. |
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_using_a_single_underscore_as_a_class_name