Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add predefined_constants to reservedNames array #42832

Conversation

AbdlrahmanSaberAbdo
Copy link
Contributor

What


This PR is for adding predefined_constants to reservedNames array in a generator command. for example:

php artisan make:model __FILE__

Why


Using PHP keywords & constants as the name when using generation commands is not only bad practice, but it simply does not even work.

For example, if there's a developer who wants to create a model called __FILE__
image

Some could say:

"Developers should just be cautious and not use keywords when scaffolding."

I partially agree, but when you use the following generation command for example:

php artisan make:model __FILE__ -a

image

And now your project is polluted with a model class, factory, migration, and seeder, while the model isn't usable in the first place. It would be much better to disallow the scaffolding immediately and prevent this.

Note


I asked myself why developers even name classes with underscores but when I checked the reservedName array I found the __halt_compiler keyword prevented before so that encourages me to add predefined_constants in PHP to prevent it also.

Screenshot


image

@taylorotwell taylorotwell merged commit edb438a into laravel:9.x Jun 17, 2022
@GrahamCampbell GrahamCampbell changed the title Add predefined_constants to reservedNames array [9.x] Add predefined_constants to reservedNames array Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants