Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114734 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63439 invoked from network); 5 Jun 2021 09:33:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jun 2021 09:33:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 66E931804E3 for ; Sat, 5 Jun 2021 02:47:39 -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=0.0 required=5.0 tests=BAYES_00,BODY_8BITS, HTML_MESSAGE,KHOP_HELO_FCRDNS,SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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 ; Sat, 5 Jun 2021 02:47:38 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 2386A5101324; Sat, 5 Jun 2021 09:47:36 +0000 (UTC) To: Nikita Popov , PHP internals References: Message-ID: <1e900fb5-4fb9-e283-de67-4fb1e035c0c8@processus.org> Date: Sat, 5 Jun 2021 11:47:35 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------DEF25D742732535B200E6A24" Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] [RFC] Readonly properties From: pierre-php@processus.org (Pierre) --------------DEF25D742732535B200E6A24 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Le 04/06/2021 à 17:19, Nikita Popov a écrit : > Hi internals, > > I'd like to open the discussion on readonly properties: > https://wiki.php.net/rfc/readonly_properties_v2 > > This proposal is similar to the > https://wiki.php.net/rfc/write_once_properties RFC that has been declined > previously. One significant difference is that the new RFC limits the scope > of initializing assignments. I think a key mistake of the previous RFC was > the confusing "write-once" framing, which is both technically correct and > quite irrelevant. > > Please see the rationale section ( > https://wiki.php.net/rfc/readonly_properties_v2#rationale) for how this > proposal relates to other RFCs and alternatives. > > Regards, > Nikita > Hello, If I understood it well you count assignments, one note thought after re-reading once again, you state: > This variant is not allowed, as the initializing assignment occurs from outside the class: Does this mean it'll prevent programmatic object hydration using the scope-stealing closure pattern ? Such as: newInstanceWithoutConstructor(); (\Closure::bind(     function (SomeClass $object) ($bar         $object->foo = $bar;     },     null,     SomeClass::class ))($object); ?> I know this is a weird stuff to do I wouldn't advise to others myself, but some hydration libraries such as ocramius/generated-hydrator do leverage this mechanism to hydrate objects, and I sometime do it myself in business code, sporadically, to hydrate objects from database without needing to define a constructor for those value objects. If it does prevent such code, will there be some additional mechanism to create value objects with readonly properties without constructor ? Such as an JavaScript object-like object instanciation mechanism ? I know this goes far outside of this RFC's own scope, but maybe this is the occasion to open a discussion about this, this would play well with readonly properties and various serializers or hydrators libraries. Regards, -- Pierre --------------DEF25D742732535B200E6A24--