Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114346 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18230 invoked from network); 10 May 2021 17:09:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 May 2021 17:09:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 223701804B5 for ; Mon, 10 May 2021 10:17:18 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 10 May 2021 10:17:17 -0700 (PDT) Received: by mail-pj1-f51.google.com with SMTP id md17so10152687pjb.0 for ; Mon, 10 May 2021 10:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a5Y4hgGD8Brm4R2v5VV09TBnY7WrvTlrxBncsn5ijqI=; b=j2J5WjybN/q2NZpE/JllnYV1ZhxoYsbY7h1Aa5SLR5D7sXRzJaAPWh6AyKBczIRKYp VVhQPf9hDLNUeuP5iSIMQzlO87Kb8YW9MkwBE38gXQT1hUzx0MRFOewjj7MFTWqqSpP7 LW796VbUrnVaZbGyLr/PXpZBPuqYYJBqvitKE7Cv/nsjTbyjBRyh1d+DqxT3J2iQOfs+ Bxe0M0/MbNX1372WRbzfc2Qb47sV8XisqJR1Ljl6LkW8KK2iJ+5q6H6DA0CkBl5V9NvL 977ReZAFI9CjIiNUg+YJLzJvhgZZtHggIfaPuuN/tWZpOYKAgSNxuVGODkaLtgUU9r5c tK4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=a5Y4hgGD8Brm4R2v5VV09TBnY7WrvTlrxBncsn5ijqI=; b=rHGq5ckHROcQJuOP2kYNh+8Ex6rsRBMfbp+VqLfJH0Z9n6ro4j0G1sfj2OsTTBZDYp Co3DKknMjQmzzJ3/Jy7om1VuOjZObzCTQkid/mtwD6r92WZKPph3zlhpcGbAiPtiJakR lCgfkreWO1nz1+JAJ9fafJ/qd/S+zsd3ixxQkuf/bPq5MB368tpMFtZF67A2AfLkXFqL dULdNN11r8TRwsDQFd4ZxZ/refiooyVpGf5d6mMm0M4uHFgdWLscjCyqGpsx3Vm5q+P8 Oomvo+t6ZZJZjpkFGZGpt7mGVcE9c6lIGUqmM0TAC9XB4LkE3E6iRHbeaJ86tTxgmHRG jidA== X-Gm-Message-State: AOAM532psDZJMLHnGmXyQ1jymIp1WpFh3GzYK1aEDkuTQBn4+JnhIgfH zSFMHC8ky7wLnswUUhiXPam0+kmketyApkpK3MUDSeaIrA80ecRH+rk= X-Google-Smtp-Source: ABdhPJxm6zv2osKW7abw2HDf6GECrv18wEpa8QmX3uvvYcNfPkrRmnwUsNY6kZUu85ZXszlb6G8j82wfp7i5NxgMZlc= X-Received: by 2002:a17:90b:958:: with SMTP id dw24mr146267pjb.185.1620667033424; Mon, 10 May 2021 10:17:13 -0700 (PDT) MIME-Version: 1.0 References: <1620635361.9147.0@gmail.com> <973730f8-1c9c-4208-b1fa-5f1048f6d6cf@www.fastmail.com> In-Reply-To: <973730f8-1c9c-4208-b1fa-5f1048f6d6cf@www.fastmail.com> Date: Mon, 10 May 2021 21:46:34 +0430 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000d396fd05c1fcf2eb" Subject: Re: [PHP-DEV] [RFC][Draft] Body-less __construct From: hossein.baghayi@gmail.com (Hossein Baghayi) --000000000000d396fd05c1fcf2eb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 __construct( private Bar $bar, private Baz $baz ); } but in my opinion, the old way of defining them is nice and concise: class Foo { private Bar $bar; private Baz $baz; } What is the point of taking the hard way and then making it convenient? On Mon, 10 May 2021 at 21:28, Larry Garfield wrote= : > On Mon, May 10, 2021, at 9:40 AM, Chase Peeler wrote: > > On Mon, May 10, 2021 at 6:31 AM Guilliam Xavier < > guilliam.xavier@gmail.com> > > wrote: > > > > > On Mon, May 10, 2021 at 10:29 AM Mat=C4=ABss Treinis > > > wrote: > > > > > > > Hi everyone, > > > > > > > > Since constructor property promotion is now implemented, and it loo= ks > > > > like it could become a widely used feature, I am proposing a small, > > > > cosmetic change in syntax for constructors in concrete classes to d= o > > > > away with empty constructor body. > > > > > > > > Here's an example of how this would work: > > > > > > > > > > > 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 usin= g > > > > empty body, just that in this case the body would be implied empty. > > > > > > > > Thoughts? > > > > Regards, > > > > - Mat=C4=ABss > > > > > > > > > > > Hi, > > > > > > To me `;` means not "empty body" (that's `{}`) but really "no > definition, > > > only declaration" (or "no body, only signature", and also "no code > > > executed"), i.e. an *abstract* method (either explicitly declared so > in a > > > class, or implicitly in an interface). > > > > > > Granted, property promotion is already special (cannot be used in an > > > abstract constructor), but it can also be mixed with non-promoted > > > parameters and body, so I feat that your proposed alternative syntax > would > > > bring more confusion than convenience :s > > > > > > Regards, > > > > > > -- > > > Guilliam Xavier > > > > > > > I'm ambivalent about this proposal, but figured I'd throw out one > advantage > > to ; over {}. In my opinion, ending with a semicolon is a very clear wa= y > of > > saying there is no body to the method, while having {} could indicate > that > > implementation of the body was intended but never actually done. I know > > that when I'm writing new classes I often will set up the method > signature > > but leave the method body empty while I finish the code that utilizes > that > > method. I don't know if that is justification for the proposal, but it = is > > one reason why ; might be preferred over {}. > > > > > > -- > > Chase Peeler > > chasepeeler@gmail.com > > 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 exceptions where all you're doing is declaring a type. > I figure that would get even more pushback, though. :-) > > As a data point, you can already do the same "semi-colon for no body" for > foreach, for, and while loops. I've only ever done it on foreach to runo= ut > an iterator, but it works on all three today. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000d396fd05c1fcf2eb--