Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107065 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62312 invoked from network); 13 Sep 2019 11:43:14 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 13 Sep 2019 11:43:14 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 3B6562CB91C for ; Fri, 13 Sep 2019 02:19:21 -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=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, KHOP_HELO_FCRDNS,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 188.165.0.0/16 X-Spam-Virus: No Received: from poczta.brzuchalski.com (ns220893.ip-188-165-245.eu [188.165.245.118]) by php-smtp3.php.net (Postfix) with ESMTP for ; Fri, 13 Sep 2019 02:19:20 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 6283A2984239 for ; Fri, 13 Sep 2019 11:19:17 +0200 (CEST) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q54lucYqF25w for ; Fri, 13 Sep 2019 11:19:15 +0200 (CEST) Received: from mail-oi1-f180.google.com (unknown [209.85.167.180]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 649BA2984236 for ; Fri, 13 Sep 2019 11:19:15 +0200 (CEST) Received: by mail-oi1-f180.google.com with SMTP id 7so1590863oip.5 for ; Fri, 13 Sep 2019 02:19:15 -0700 (PDT) X-Gm-Message-State: APjAAAWIvboI0rFIurYVpxBlDyjXbUFsnoObo+jYyAf51fCBeS/4s3KZ 6ON25gQq1SijVqfYLqkZ6htJzX/EQkchjwD1yDI= X-Google-Smtp-Source: APXvYqyPyWe2GYDJr7i8amEjg4Nb3t6zovX1y9OEwSS/I/eXb8uSEzEjhb7/lUMjQ7HHeAmidVXMnIADuaLKH7G5klk= X-Received: by 2002:a05:6808:243:: with SMTP id m3mr2267132oie.101.1568366354188; Fri, 13 Sep 2019 02:19:14 -0700 (PDT) MIME-Version: 1.0 References: <74C03BB1-28DF-4694-A91D-2516C545F8B2@gmail.com> <3CA484B0-BCA3-4A2B-B2A6-8B845F9C462B@newclarity.net> In-Reply-To: Date: Fri, 13 Sep 2019 11:19:02 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Arnold Daniels Cc: PHP Internals Content-Type: multipart/alternative; boundary="0000000000006b4f4b05926bbf2c" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Object Initializer From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --0000000000006b4f4b05926bbf2c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Arnold, pt., 13 wrz 2019 o 10:51 Arnold Daniels napisa=C5=82(a): > This can easily be done in a number of ways, like the suggested helper > function. The same can be said for many other features that were > implemented recently, like array unpacking. This feature is easy to > implement and will make the code for data objects much more readable, wit= h > additional benefits for static analysis. > > Comments: > > I don't like how it works for anonymous classes. It's more difficult to > implement since the compiler doesn't know the meaning of the (first) > bracket. It's doesn't make the code more readable, for the same reason. I > think it's better to not support this syntax with anonymous classes. > > Probably lexical scope for anon classes would be better here, but due to fact that proposal is to use initializer block instead of constructor arguments, that was the reason why initializer block got before anon class definitions. > The examples do not show how constructor arguments are passed. I'm assumi= ng > it's > > $customer =3D new Customer("foo") { > name =3D "John" > }; > > The examples don't show that cause it's forbidden. There is a note on that in RFC on purpose > Note! Object instantiation allows only constructors without required arguments to be used. > Any class which requires passing arguments to constructor cannot be used in combination with object initializer. Using constructor arguments and object initializer would introduce noise and you'll be potentially initializing object twice: using object initializer block and using constructor args what may be misleading. > About the idea of letting `{ foo =3D 10 }` create an `stdClass` object (n= ot > in the RFC); While not used much since it has no effect, it's perfectly > okay to put your code in brackets eg `{ { { $foo =3D 10; } } }`. As such,= I > don't think it's a good idea to allow `new stdClass` to be omitted. > Future scope mentions only about letting to create stdClass with omitting of the class name only, nothing said about removing a new keyword. Thanks, Micha=C5=82 Brzuchalski --0000000000006b4f4b05926bbf2c--