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

2021-05-11 Thread Nikita Popov
On Tue, May 11, 2021 at 6:56 PM Matt Fonda wrote: > On Tue, May 11, 2021 at 7:45 AM Nikita Popov wrote: > >> My thought here is that a constructor with (only) promoted properties is >> hardly a constructor at all -- it's more like a special syntax for >> declaring properties that happens to re-u

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

2021-05-11 Thread Matt Fonda
On Tue, May 11, 2021 at 7:45 AM Nikita Popov wrote: > My thought here is that a constructor with (only) promoted properties is > hardly a constructor at all -- it's more like a special syntax for > declaring properties that happens to re-use the constructor notation, > because that allows it gene

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

2021-05-11 Thread Guilliam Xavier
On Tue, May 11, 2021 at 5:07 PM Pierre wrote: > Le 10/05/2021 à 18:58, Larry Garfield a écrit : > > > I agree that in the grand scheme of things this would be a minor matter, > but aesthetically I would prefer it as well. The {} annoys me, CS tools or > no. > > > > Related: I feel the same way a

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

2021-05-11 Thread Pierre
Le 10/05/2021 à 18:58, Larry Garfield a écrit : I agree that in the grand scheme of things this would be a minor matter, but aesthetically I would prefer it as well. The {} annoys me, CS tools or no. Related: I feel the same way about empty-classes and interfaces, which is often the case for

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

2021-05-11 Thread Pierre
Le 11/05/2021 à 16:50, Chase Peeler a écrit : On Tue, May 11, 2021 at 10:48 AM Matīss Treinis wrote: Hi Sara, > While it's certainly silly/pointless to have a nil constructor when there are non-promoted args present, I think that deliberately making that mode special (read: inconsistent) is

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

2021-05-11 Thread Chase Peeler
On Tue, May 11, 2021 at 10:48 AM Matīss Treinis wrote: > Hi Sara, > > > While it's certainly silly/pointless to have a nil constructor when > there are non-promoted args present, I think that deliberately making > that mode special (read: inconsistent) is the wrong way to go. > > Sorry, but I do

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

2021-05-11 Thread Matīss Treinis
Hi Sara, > While it's certainly silly/pointless to have a nil constructor when there are non-promoted args present, I think that deliberately making that mode special (read: inconsistent) is the wrong way to go. Sorry, but I don't follow - so you would prefer that this: public function __

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

2021-05-11 Thread Pierre
Le 11/05/2021 à 16:39, Chase Peeler a écrit : I agree. I think making things inconsistent between constructors and other methods is something that can be lived with - there are already other things special about constructors that don't apply to other methods - but we should at least allow consist

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

2021-05-11 Thread Nikita Popov
On Tue, May 11, 2021 at 4:37 PM Côme Chilliet < come.chill...@fusiondirectory.org> wrote: > Le Tue, 11 May 2021 10:58:57 +0200, > Nikita Popov a écrit : > > > If we allow it, I would restrict it to specifically the case of a) a > > promoted constructor b) which has *only* promoted parameters. I d

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

2021-05-11 Thread Chase Peeler
On Tue, May 11, 2021 at 10:34 AM Sara Golemon wrote: > On Tue, May 11, 2021 at 5:18 AM Matīss Treinis > wrote: > > Yes, just to clarify the scope of my initial proposal, this should only > > ever apply to promoted constructors that have 1 or more promoted > > parameters, and no not-promoted para

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

2021-05-11 Thread Côme Chilliet
Le Tue, 11 May 2021 10:58:57 +0200, Nikita Popov a écrit : > If we allow it, I would restrict it to specifically the case of a) a > promoted constructor b) which has *only* promoted parameters. I don't think > we should allow replacing "{}" with ";" for methods in the general case. This would cr

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

2021-05-11 Thread Sara Golemon
On Tue, May 11, 2021 at 5:18 AM Matīss Treinis wrote: > Yes, just to clarify the scope of my initial proposal, this should only > ever apply to promoted constructors that have 1 or more promoted > parameters, and no not-promoted parameters. > Hard disagree. While it's certainly silly/pointless to

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

2021-05-11 Thread Matīss Treinis
Oh absolutely, and many thanks for doing the code part, Nikita! I would propose leaving this open for debate till, say, 15th of May here on internals ML to gather more input. If there are no super strong arguments on why this should not happen or go to RFC, I will draft a RFC and from there, the

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

2021-05-11 Thread Bruce Weirdan
> If we allow it, I would restrict it to specifically the case of a) a > promoted constructor b) which has *only* promoted parameters. I don't think > we should allow replacing "{}" with ";" for methods in the general case. It could also be useful when you want to make sure constructor is *not* de

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

2021-05-11 Thread Nikita Popov
On Tue, May 11, 2021 at 12:17 PM Matīss Treinis wrote: > Yes, just to clarify the scope of my initial proposal, this should only > ever apply to promoted constructors that have 1 or more promoted > parameters, and no not-promoted parameters. > > These would NOT be considered valid: > > public

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

2021-05-11 Thread Matīss Treinis
Yes, just to clarify the scope of my initial proposal, this should only ever apply to promoted constructors that have 1 or more promoted parameters, and no not-promoted parameters. These would NOT be considered valid: public function __construct( private Baz $baz, Bar $bar

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

2021-05-11 Thread Nikita Popov
On Mon, May 10, 2021 at 10:29 AM Matīss Treinis 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

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

2021-05-10 Thread Marco Sirabella
On Mon, May 10, 2021 at 01:22:46PM -0500, Ben Ramsey wrote: > Hossein Baghayi wrote on 5/10/21 13:01: > > On Mon, 10 May 2021 at 21:59, Larry Garfield wrote: > > > > > 1) Please don't top-post. > > > > > > > > Sorry for top-posting. Didn't know what it means :), also it was kind of my > > first

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

2021-05-10 Thread Ben Ramsey
Hossein Baghayi wrote on 5/10/21 13:01: > On Mon, 10 May 2021 at 21:59, Larry Garfield wrote: > >> 1) Please don't top-post. >> >> > Sorry for top-posting. Didn't know what it means :), also it was kind of my > first reply to mailing list. https://github.com/php/php-src/blob/master/docs/mailing

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

2021-05-10 Thread Hossein Baghayi
On Mon, 10 May 2021 at 21:59, Larry Garfield wrote: > 1) Please don't top-post. > > 2) The reason is that the old way doesn't provide any way to populate them > on construction. The pattern of "assign the arg to the prop in the > constructor" is stupendously common, and promotion makes it vastly

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

2021-05-10 Thread Larry Garfield
On Mon, May 10, 2021, at 12:16 PM, Hossein Baghayi wrote: > If constructor is supposed to be empty then why are we even bothering with > construction promoting style? Why aren't we sticking to the old way of > defining properties? > Are there any advantages to using construction promoting style? >

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

2021-05-10 Thread Sara Golemon
On Mon, May 10, 2021 at 3:56 AM Marco Pivetta wrote: > > 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 > > ther

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

2021-05-10 Thread Hossein Baghayi
If constructor is supposed to be empty then why are we even bothering with construction promoting style? Why aren't we sticking to the old way of defining properties? Are there any advantages to using construction promoting style? I mean sure we could have this: class Foo { public function __c

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

2021-05-10 Thread Larry Garfield
On Mon, May 10, 2021, at 9:40 AM, Chase Peeler wrote: > On Mon, May 10, 2021 at 6:31 AM Guilliam Xavier > wrote: > > > On Mon, May 10, 2021 at 10:29 AM Matīss Treinis > > wrote: > > > > > Hi everyone, > > > > > > Since constructor property promotion is now implemented, and it looks > > > like it

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

2021-05-10 Thread Chase Peeler
On Mon, May 10, 2021 at 6:31 AM Guilliam Xavier wrote: > On Mon, May 10, 2021 at 10:29 AM Matīss Treinis > 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

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

2021-05-10 Thread Guilliam Xavier
On Mon, May 10, 2021 at 10:29 AM Matīss Treinis 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

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

2021-05-10 Thread Marco Pivetta
Hey Matīss On Mon, May 10, 2021 at 11:12 AM Matīss Treinis wrote: > I don't necessarily agree with this point in particular - I mentioned PSR > just-by-driveby, since whoever does follow that convention will face this > issue - but the scope of the proposal is not

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

2021-05-10 Thread Matīss Treinis
I don't necessarily agree with this point in particular - I mentioned PSR just-by-driveby, since whoever does follow that convention will face this issue - but the scope of the proposal is not limited to PSR adopters. It's also worth pointing out that PSR is not an "official" coding guideline for P

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

2021-05-10 Thread Aleksander Machniak
On 10.05.2021 10:49, Matīss Treinis wrote: > 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. > >

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

2021-05-10 Thread Marco Pivetta
On Mon, May 10, 2021 at 10:50 AM Matīss Treinis wrote: > 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

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

2021-05-10 Thread Ilija Tovilo
Hi internals On Mon, May 10, 2021 at 10:32 AM Marco Pivetta wrote: > > Hey Matīss, > > This already works by replacing `;` with `{}`: https://3v4l.org/tN4HM > > Is the change in AST really necessary, considering that? The root problem is not that {} is significantly worse than ; but it's that so

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

2021-05-10 Thread Matīss Treinis
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. Anot

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

2021-05-10 Thread Marco Pivetta
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 wrote: > Hi everyone, > > Since c

[PHP-DEV] [RFC][Draft] Body-less __construct

2021-05-10 Thread Matīss Treinis
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 wo