Hi Marco,

I am not sure, that's why I am asking for feedback.

I have been converting a ton of code to use constructor property promotion
and the absolute majority ends up with the method body being empty. I
reckon this could be a nice eye-candy to have, however, it's nothing more
than that.

Another point to be made here, as far as my interpretation of PSR-12, the
curly braces occupy two lines for methods with multiline arguments. So for
whoever follows PSR-12, it's more like this, with brackets just dangling
there across 2 lines.

[...]
class Foo {
    public function __construct(
        private Bar $bar,
        private Baz $baz
    ) {
    }
}



- Matīss


On Mon, May 10, 2021 at 10:31 AM Marco Pivetta <ocram...@gmail.com> wrote:

> 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 <mrtrei...@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
>>
>>

Reply via email to