On Fri, Jul 19, 2024 at 1:34 AM Oliver Nybroe <olivernyb...@gmail.com>
wrote:

> Hello internals.
>
> I am looking into making the constructor body optional in classes,
> essentially allowing you to write
>
> ```
> class User {
>     public function __construct(
>         private string $name,
>     )
> }
> ```
>
> Currently to make this code valid, it would have to be written the
> following way
>
> ```
> class User {
>     public function __construct(
>         public string $name,
>     ) {}
> }
> ```
>
> 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 change would only be a cosmetic change and simplify the userland code
> by removing two redundant characters.
>
>
>
> This would be my first RFC and I am willing to try and implement it
> myself.
>
>
> Best regards
> Oliver Nybroe (he/him)
>


FWIW, there is already a PR for it (
https://github.com/php/php-src/issues/8420) which also contains the RFC
draft.

Kind regards,
Faizan

Reply via email to