Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120299 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2505 invoked from network); 15 May 2023 18:49:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 May 2023 18:49:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9386B18056B for ; Mon, 15 May 2023 11:49:31 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 15 May 2023 11:49:31 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 474705C02F4 for ; Mon, 15 May 2023 14:49:31 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Mon, 15 May 2023 14:49:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1684176571; x= 1684262971; bh=kj8ZtRRQENRGEekb4NCPqj57Df77R2vVZkothBA7tY4=; b=R 4Ecg/nxyKFuUy0Z3YU7xrE7lW5fne/7Mm9SofKf7+vNS4u6pj+ouh06C0hzAKQRH nGObTAjWunXsf+XcCZXVtiLCwJhNCrwPxsQxwrG48GyIRtnE+MgokG+tGD6PVhqy b1hsyZ+Tq+OXtRKZnW10oqb3uhzmy95/AOVk1vnEScTT4gCHQx9rTm2oGwJBNUOT ise91X7/noaUfZGmB6fmrDP+B0sx6dy9o2ZPiVh7VK42Xtvrjdk/75EIbxw6QJZB CoKi/uFp228aAUCezJgAgSfd74r4LFYosqyifowVya4THpJKxmKeyDpoeBG11gTi RKedNujHntKG+I/zyx4mw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1684176571; x=1684262971; bh=kj8ZtRRQENRGE ekb4NCPqj57Df77R2vVZkothBA7tY4=; b=tPa0N6bsiu+gigwy5USfeYZSeA5EY sF9wjEw515sLanrpcGKC05BQ4v4QZkoxFMiG6cTc7nvS4VokX/r+8m44RXu7+xCx pUplPCvUgqlhWgNNG47Ju/arou9sDi5CIBDk5hLGFpoycQ6ietDhjxj0ZoIxMLig NG4Q+l0mPCHFPnv8NloViPXsj+U9KcD1TvLEMVaeSG3LADoKA6gpWH2HKDgEAzM3 jWsDm6r6n0dhSaOFNWQBimXPtYe7ukLJoSn49W47XH2DZ9i+WE3YeiWr+B0qNR4L x4ehJyHe1AHYCgkx0hOE6c2ZpwJxbXboYCvrztia4Ec+zDludjxAdcT9g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehjedgudefvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0FE7E1700089; Mon, 15 May 2023 14:49:31 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-415-gf2b17fe6c3-fm-20230503.001-gf2b17fe6 Mime-Version: 1.0 Message-ID: <34f79079-3ddd-4393-86f3-83afbca00ba6@app.fastmail.com> In-Reply-To: References: <641b1ca0-d33f-4f38-ae64-81b4abce24da@app.fastmail.com> Date: Mon, 15 May 2023 18:49:10 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Property hooks, nee accessors From: larry@garfieldtech.com ("Larry Garfield") On Mon, May 15, 2023, at 8:32 AM, Lynn wrote: > It's starting to get crowded in object constructors. The following example > is so much more readable and maintainable imo. Would it be possible to > still add the quick assignment as a language feature? I'm personally not > happy having property definitions in both the class body _and_ the > constructor signature. > > ```php > class User { > private string $first; > private string $last; > public string $fullName { > get => $this->first . ' ' . $this->last; > set => [$this->first, $this->last] = explode(' ', $value, 2); > } > > public function __construct($this->fullName) {} > } > > // vs > > class User { > private string $first; > private string $last; > > public function __construct( > public string $fullName { > get => $this->first . ' ' . $this->last; > set => [$this->first, $this->last] = explode(' ', $value, 2); > } > ) {} > } > > // or > > class User { > private string $first; > private string $last; > public string $fullName { > get => $this->first . ' ' . $this->last; > set => [$this->first, $this->last] = explode(' ', $value, 2); > } > > public function __construct(string $fullName) > { > $this->fullName = $fullName; > } > } The last version skips constructor promotion entirely, so will absolutely work. For this case, that's frankly the best approach, since you're right, the constructor gets rather messy otherwise. Changing the syntax and semantics for CPP itself (as in the first code block above) is considerably out of scope for this RFC. I recall someone pointing out why double-declaring the property would cause problems, but I forget the reason. In any case, another promotion syntax would be a topic for another RFC. I don't recall off hand the reasons Nikita had for choosing the syntax that ended up being used. --Larry Garfield