Re: [RFC][Draft] Body-less __construct

From: Date: Mon, 10 May 2021 08:31:41 +0000
Subject: Re: [RFC][Draft] Body-less __construct
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-114325@lists.php.net to get a copy of this message
Hey Matīss,

This already works by replacing ; with {}: https://3v4l.org/tN4HM

Is the change in AST really necessary, considering that?

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On Mon, May 10, 2021 at 10:29 AM Matīss Treinis <mrtreinis@gmail.com> wrote:

> Hi everyone,
>
> Since constructor property promotion is now implemented, and it looks
> like it could become a widely used feature, I am proposing a small,
> cosmetic change in syntax for constructors in concrete classes to do
> away with empty constructor body.
>
> Here's an example of how this would work:
>
> <?php
> namespace App;
>
> class Foo {
>     public function __construct(
>         private Bar $bar,
>         private Baz $baz
>     );
> }
>
> Some notes to this:
>
> - Since this is similar to already existing syntax for body-less
> methods, parser should not be affected that much. I hope. I really have
> no idea.
> - Syntax would be optional - meaning, you can as well continue using
> empty body, just that in this case the body would be implied empty.
>
> Thoughts?
> Regards,
> - Matīss
>
>


Thread (34 messages)

« previous php.internals (#114325) next »