Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109122 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32261 invoked from network); 18 Mar 2020 07:04:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Mar 2020 07:04:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B8D491804F3 for ; Tue, 17 Mar 2020 22:27:34 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 ; Tue, 17 Mar 2020 22:27:34 -0700 (PDT) Received: by mail-ot1-f44.google.com with SMTP id r2so8867928otn.6 for ; Tue, 17 Mar 2020 22:27:34 -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=ti8zH8ZiJO9QQxzHvY2hEMo71f2bBE67U1qOP3XMvgQ=; b=ajqlGbx+26j6EOCrsB7PFcPtGuKxzhk0+hLINhcws2XKf9N7HTHl6ug08qU+LkcrMD 1i05g5UfybVzYLMSbr/VpSYXNowfBYX9RvjWTFHqVJWLy++2Eds1K07g6UhyIo57mWoo PZCTy7MBpX+iVUtXzDxiVRutQeugaMPHK0s2NcpDjf4Y2mbjfZh/YX8pHRXHlc4awV69 3fM5+0Qlby+Z0b8ZP3FqgoFi4yOk+0+FbjsR8cEMDxCOoP89u4mKzmVf0JlJ+7Lbn1XJ euDWpflM7visVzsufzubeKqbT+AfeeJnaWPdjwhwrQUJno5J4jH4zgzkFWmOeJIbdqHR +U+w== 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=ti8zH8ZiJO9QQxzHvY2hEMo71f2bBE67U1qOP3XMvgQ=; b=IT3eeVRlfuW2VlGMTuN0ocrgZ8l+Y/TQLlHBAswzHCFE4E6Us24knTOEhjvFY1ZEOi X1hTehicF1OVGJJn3vewH8k0qxpz9SRjQmLKzFiSDJU9dvPGQrqUeDgXxo/TjUZ02agD KQ7vFouK3FIkrAK7RDIXHQLqSyzyQPioarviWZ3WCmUnZS2Hz9o2SXToMwPSBMrayy62 6wx4StU6p1AxGSW067OoTxmVrphCmRiiF6SQd/HtpGlgRQmsJJdCXoHuYlBBezdNPXnX 7Q5lv1/VPDsEacHlK+AadqIM/m7aR7ycDiGmeFJVcAKaEIEGLpkFvWddVAwuXdKTg5To lLLw== X-Gm-Message-State: ANhLgQ1B94/T0SlCFHrjhWsDfAnbJLTKp3LDvxsS6US47BI3ZGbZIVs6 EWU9LQuU8qfQwL7kXXK7+gOTdCWqkeZMOJSNJkMLfV3tqrg= X-Google-Smtp-Source: ADFU+vuKPblASjKA94AkOZirTB4+2w3U3W59/TrcjjxTBgBVRzvG8Uwexaq+oBr52MUCgYvMGAyOZ2JLOSNS16N8w+M= X-Received: by 2002:a9d:6c0b:: with SMTP id f11mr2355539otq.182.1584509252408; Tue, 17 Mar 2020 22:27:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 18 Mar 2020 06:27:19 +0100 Message-ID: To: Jakob Givoni Cc: php internals Content-Type: multipart/alternative; boundary="000000000000221a6f05a11a4f27" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Compact Object Property Assignment From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --000000000000221a6f05a11a4f27 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =C5=9Br., 18 mar 2020, 03:36 u=C5=BCytkownik Jakob Givoni = napisa=C5=82: > Thank you, Micha=C5=82, for chiming in :-) > > On Tue, Mar 17, 2020 at 10:52 AM Micha=C5=82 Brzuchalski > wrote: > > For object initializer, I was hoping to introduce a feature which with > the benefits of typed properties > > could reduce the boilerplate on initializing object and setting their > properties in one expression. > Exactly my motivation with COPA as well; > - Typed properties - check, > - Reduce boilerplate - check, > - Initializing and setting properties in one expression - check. > > > With object initializer, this could be reduced to: > > > > $this->dispatch(new SomeCommand { foo =3D 'bar', baz =3D false }); > And with COPA it would be; > $this->dispatch((new SomeCommand)->[ foo =3D 'bar', baz =3D false ]); > Subtle differences, when compared to the currently available alternative. > The difference is in object state initialization : Using Object Initializer enforce that if a class is instantiated with the Object Initializer, at the end of the instantiation and properties initialization, all visible properties *(depends on initialization scope)* = are initialized, otherwise, a RuntimeException is thrown. This helps to avoid bugs where a property is added to the class but forgot to be assigned it a value in all cases where the class is instantiated and initialized. https://wiki.php.net/rfc/object-initializer#restrictions You can't do that with COPA cause it has nothing to do with object instantiation. > > But as mentioned IMO this is a different feature than what you propose > and personally I see no point > > in reducing only assignment statements without combining it with object > construction for these kinds > > of small objects, DTO's, commands, queries and events. > Maybe you missed that COPA can be combined with object construction? > > > but personally I don't need a constructor at all in those cases since w= e > > have typed properties and it looks like they could be also marked as > read-only in next major PHP version. > Exactly, and as I couldn't help notice that you voted for the Write > Once Properties RFC, which clearly states that > object construction is a fuzzy term (meaning don't take it too > seriously) and lazy initialization is a feature... > > I hope you will either reconsider your support for COPA or let me know > what I'm missing so I can > consider other directions. > --000000000000221a6f05a11a4f27--