Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114348 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22100 invoked from network); 10 May 2021 17:21:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 May 2021 17:21:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 64A751804D8 for ; Mon, 10 May 2021 10:29:02 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 10 May 2021 10:29:01 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 96A485C013F for ; Mon, 10 May 2021 13:29:01 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Mon, 10 May 2021 13:29:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=8fk2Cp GlktALVB9ZcTthMhyJFNZARRPJSOImV9txha0=; b=fUElFbbzPonJwDD6/oS/1a tYFLjVxMGB7vpl6tZ6OdCLCZPM2MXcKO9pevuG575peV/sU5+pa3vRR2N3gi8CBR JF4vNv+L9bGi1yPzsmaufO4tYIjKLq9l/uHN0gBhqlHzqb8Khsa2RNdeRCqPN0WT KaRaaE1gMoh9PXHi0P3dGhGrp4biK1y9DOepL93RkqtB27jCSia83sDVLvUDGebC ZwkzmvawGQtv9shGd2QgzrgVaJXw4oVsLcakYeOccOgQXDMjySS/O1q6KKTuCFv5 wKN/j77IRacUSyW5Qfl2dL0c3DcextZCVty7cY0qA1xtMNPF4mW6qXTMVJOoMZRw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdegkedguddugecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepfedvtdettdfgteegleduudeuleefieffuddtffek hfeviedtjedvgeekiedvledunecuffhomhgrihhnpehplhgrthhfohhrmhdrshhhnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhies ghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 18E9C3A04D9; Mon, 10 May 2021 13:29:01 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 Mime-Version: 1.0 Message-ID: <4f7a4163-1eaf-404f-8d91-636722aa27b7@www.fastmail.com> In-Reply-To: References: <1620635361.9147.0@gmail.com> <973730f8-1c9c-4208-b1fa-5f1048f6d6cf@www.fastmail.com> Date: Mon, 10 May 2021 12:28:40 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC][Draft] Body-less __construct From: larry@garfieldtech.com ("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? > > 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? 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 more convenient. For more details: https://platform.sh/blog/2020/php-80-feature-focus-constructor-property-promotion/ The constructor isn't "supposed" to be empty. It just often is with promotion, because the constructor wasn't doing anything else besides shuffling its parameters over to properties, which is now automatic. --Larry Garfield