Improve class name checking in GeneratorCommand#38965
Improve class name checking in GeneratorCommand#38965schrosis wants to merge 4 commits intolaravel:8.xfrom schrosis:8.x
Conversation
The regular expression used can be found here https://www.php.net/manual/en/language.oop5.basic.php
| 'isset', | ||
| 'iterable', | ||
| 'list', | ||
| 'match', |
There was a problem hiding this comment.
mixed is also reserved
There was a problem hiding this comment.
Thanks for the review!
As you said, mixed seems to work as a reserved word as well.
I also found a PR in the language documentation.
php/doc-en#938
Likewise, it looks like never will be added in PHP 8.1!
- Class https://3v4l.org/8sXc6
- Interfaces https://3v4l.org/M0RSh
- trait https://3v4l.org/tEIT2
|
I'm not particularly interested in these types of checks. It is up to the user to not create invalid class names. |
|
@taylorotwell However, there is already a check for incomplete reserved words. While I think it's the user's responsibility to avoid creating invalid class names, on the other hand, as mentioned in the PR where the reserved word check was added, it's not elegant to have the process fail in the middle and leave a contaminated file. For that reason, I think it's a good idea to be able to check beforehand! |
Summary
Support for class names with subdirectories
GeneratorCommandchecks if the given name is a reserved word.However, a name with a subdirectory will pass this check.

Changed to check for simple class names without the subdirectory part.
Checking for valid class names as PHP
This change will check for invalid class names such as
2021MyClassString+HelperThe regular expression used can be found here.
https://www.php.net/manual/en/language.oop5.basic.php
Add reserved words
Add missing reserved words and reserved words to be added in PHP 8.1.
intfloatboolstringtruefalsenullvoiditerableobjectmatchenumreadonlyhttps://www.php.net/manual/en/reserved.other-reserved-words.php
https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L136
https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L166
https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L157
Screenshot
I'm new to contributing to OSS, so please let me know if I'm missing anything.