Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107108 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50253 invoked from network); 15 Sep 2019 16:12:13 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 15 Sep 2019 16:12:13 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 713642CE19C for ; Sun, 15 Sep 2019 06:48:51 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29169 217.70.176.0/20 X-Spam-Virus: No Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Sun, 15 Sep 2019 06:48:50 -0700 (PDT) X-Originating-IP: 107.223.28.39 Received: from [192.168.1.85] (107-223-28-39.lightspeed.nsvltn.sbcglobal.net [107.223.28.39]) (Authenticated sender: pmjones@pmjones.io) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id F2BF020007; Sun, 15 Sep 2019 13:48:48 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) In-Reply-To: Date: Sun, 15 Sep 2019 08:48:45 -0500 Cc: PHP Internals List Content-Transfer-Encoding: quoted-printable Message-ID: <18D5453E-D962-467C-A50C-52658C11BB25@pmjones.io> References: To: =?utf-8?Q?Micha=C5=82_Brzuchalski?= X-Mailer: Apple Mail (2.3445.9.1) X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Object Initializer From: pmjones@pmjones.io ("Paul M. Jones") > On Sep 12, 2019, at 09:00, Micha=C5=82 Brzuchalski = wrote: >=20 > Hi internals, >=20 > I'd like to open discussion about RFC: Object Initializer. >=20 > This proposal reduces boilerplate of object instantiation and = properties > initialization in case of classes without required constructor = arguments as > a single expression with initializer block. >=20 > https://wiki.php.net/rfc/object-initializer This reminds me of how Hack/HHVM would initialize object properties from = constructor parameters; I remember finding it very appealing. IIRC, you would provide the property signature as a constructor = parameter to trigger the initialization: ```php class Foo { protected int $bar; public function __construct(protected int $bar) { } public function getBar() : int { return $this->bar; } } $foo =3D new Foo(1); echo $foo->getBar(); // 1 ``` Perhaps something like that is worth adopting here. --=20 Paul M. Jones pmjones@pmjones.io http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php