-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Feature Request: Enhanced Syntax for Property Declarations... #17029
Comments
Hi @DxBang. I don't understand, this is already how it works (minus the JSON thing). https://3v4l.org/Yu7nk |
Ah, yes, that one works, I just didn't read the error message correctly when I was testing it... I had 2 $a, DU'H!! I will remove part 2, thanks :) |
See https://wiki.php.net/rfc/compact-object-property-assignment, for prior art. I have no particular opinion on the the visibility grouping proposal. In any way, this requires the RFC process. |
This clashes with your other suggestion. How do we know if I'm pretty sure there have also been proposals for adding the |
There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests. |
I would like to request the addition of a syntax feature in PHP that allows grouping multiple properties with the same type in a class, improving code readability and reducing repetition in class definitions. This feature would be similar to the ability to declare properties in a single line with type hints introduced in PHP 7.4, but with the added flexibility to group them logically by type.
For a long time we have been able to do:
As long as we didn't give it a typed property, but since 7.4 we had to declare the visibility modifiers every time if we wanted to have typed properties on them.
The Proposal
Grouped Property Declarations with Type Hints
PHP currently supports declaring properties either with type hints introduced in PHP 7.4 or without type hints using a grouped style. However, a hybrid syntax combining both would simplify code readability and maintenance.
A mixture of both.
A bit similar to, but without the type grouping.
Benefits:
Improved readability: Grouping related properties by type would make class definitions easier to scan, especially in larger classes.
Reduced repetition: Reduces the need to repeat the type declaration for each property, making the code more concise.
Better maintainability: It's easier to spot and manage changes for properties that share the same type.
And it would also be nice if we could create simple JSON-like objects directly instead of building them in __construct() and why not allow { } to create objects instead of (object) [ ]? It is something we are used to from JSON.
Thanks and happy coding!
The text was updated successfully, but these errors were encountered: