This RFC proposes the optional of having constructors without a body.
With the introduction or constructor property promotion in 8.0, we often see classes where the constructor has an empty body, and my guess would be that this will only increase with the introduction of property access hooks in 8.4 which is allowed to be defined in the constructor also. This means most code ends up with a constructor that has `{}` at the end, to create an empty body. The readability of it is not very nice and from many coding styles this ends up being split into multiple lines.
```
class User {
public function __construct( private string $name, ) { }
}
```
This RFC proposed a short syntax which is purely a coding style choice as an alternative ```
class User {
public function __construct( private string $name, );
}
```
All the features and examples of the proposal.
To paraphrase Zeev Suraski, explain hows the proposal brings substantial value to be considered for inclusion in one of the world's most popular programming languages.
Remember that the RFC contents should be easily reusable in the PHP Documentation.
If applicable, you may wish to use the language specification as a reference.
What breaks, and what is the justification for it?
PHP 8.4
Describe the impact to CLI, Development web server, embedded PHP etc.
Will existing extensions be affected?
It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP.
Please explain how you have verified your RFC's compatibility with opcache.
Make sure there are no open issues when the vote starts!
List existing areas/features of PHP that will not be changed by the RFC.
This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.
As this RFC is following the same syntax for definitions with no bodies as interfaces uses, future proposals could be centered around making body optional in other definitions.
- Making all methods have an optional body. Could be useful for when implementing a method from an interface where your implementation should not do anything, or for changing signature on a method without touching the logic.
```php class User implements Deletable {
public function delete();
} ```
- Making classes have an optional body Having no body on a class would be very useful for custom exceptions as often, no body is needed for them.
``` class DaemonNotFoundException extends RuntimeException; ```
This section details areas where the feature might be improved in future, but that are not currently proposed in this RFC.
Include these so readers know where you are heading and can discuss the proposed voting options.
Links to any external patches and tests go here.
If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed.
Make it clear if the patch is intended to be the final patch, or is just a prototype.
For changes affecting the core language, you should also provide a patch for the language specification.
After the project is implemented, this section should contain
Links to external references, discussions or RFCs
Keep this updated with features that were discussed on the mail lists.