Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114736 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66894 invoked from network); 5 Jun 2021 09:53:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jun 2021 09:53:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9994B1804CC for ; Sat, 5 Jun 2021 03:07:19 -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_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 03:07:18 -0700 (PDT) Received: by mail-lf1-f41.google.com with SMTP id n12so10815158lft.10 for ; Sat, 05 Jun 2021 03:07:18 -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=VYCB2RR29iGisdAYIfrd0LQEezeuEzCQLQW8IqvfwkE=; b=Tb4M182vR56YUYh2VccqJAp/goglqt4qfuG0J/3tQyYJgVyKMPIMftCS7m/JuiAb5H v2UJdLX9m5oC7jE0NGM9XRCriAAMr0YP3kjYL1WZircbVEYmJUiU1MqyyUfeQ2kPVtN8 dGeOK71T9DFbNK5SAKpmx4oVCr5ENU0IWcLkIfrLpSYnv5eZFgZzPgCv9GwW2tAD+w7Y OfhaVqbIMwP6cUjVvBUUY0gB31EbOWsF48vdbfUcjWOmqBfUx8kAqUphcARduR0IFpB7 hFKIpAOydeOx3K724Q4clOMD9XwpE+0PgUFk6tW9U2W6RSK0punMUa/LHJSxgwmHZePd TFOw== 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=VYCB2RR29iGisdAYIfrd0LQEezeuEzCQLQW8IqvfwkE=; b=SVgA6oNO0LrfIvdc6CmhqGVLPPxqZ/mteuwWczvsogJUJd1jVpOvlrZfModD5cX6gD JImfP3HOIJTsH9Pneh8dUFMUa55lesBUSKNStQr5JkupD6+kdW30Esvg9M65WhkgfTUF +ymNYckjhL7BWIdZOOjq+3my6XqZwROy5ozTctJeo7npAULmOWYJ99VjnwdpQMWiVtHR wDRtawDbNSCdaQ/DYB29mxBrCX8iUF6GxbDe048iicnEfH0ljxJw3QZvq308n82TpvRl yCh7dtugGpbKEr+nRr1fgWrW8GDwIVe7zUjhgVxLiHojufOr4bWumk07kxw6lmkIPhoK gGqw== X-Gm-Message-State: AOAM533Uh9b2mnJVqcCU7oYg3xF/f6YQgCsWOZWvCblh0NATrWKfxEvd BfJ0MS4tH33rOAOGGdBXJovaRMP13zKhv29dKAwpvDT3HrM= X-Google-Smtp-Source: ABdhPJwFVWOE1p82rlUSSFO05lmp5xgbdiAOW+Zftbz/1yZteqRYmNjLcztLsZ4vd4Qas4Bf4n4CTWXI/n2skG91T9c= X-Received: by 2002:a05:6512:70d:: with SMTP id b13mr5496669lfs.315.1622887635628; Sat, 05 Jun 2021 03:07:15 -0700 (PDT) MIME-Version: 1.0 References: <1e900fb5-4fb9-e283-de67-4fb1e035c0c8@processus.org> In-Reply-To: <1e900fb5-4fb9-e283-de67-4fb1e035c0c8@processus.org> Date: Sat, 5 Jun 2021 12:06:59 +0200 Message-ID: To: Pierre Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000008365505c401f951" Subject: Re: [PHP-DEV] [RFC] Readonly properties From: nikita.ppv@gmail.com (Nikita Popov) --00000000000008365505c401f951 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jun 5, 2021 at 11:47 AM Pierre wrote: > Le 04/06/2021 =C3=A0 17:19, Nikita Popov a =C3=A9crit : > > Hi internals, > > I'd like to open the discussion on readonly properties:https://wiki.php.n= et/rfc/readonly_properties_v2 > > This proposal is similar to thehttps://wiki.php.net/rfc/write_once_proper= ties RFC that has been declined > previously. One significant difference is that the new RFC limits the sco= pe > of initializing assignments. I think a key mistake of the previous RFC wa= s > the confusing "write-once" framing, which is both technically correct and > quite irrelevant. > > Please see the rationale section (https://wiki.php.net/rfc/readonly_prope= rties_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: > > > class SomeClass > { > public readonly int $foo; > } > > $bar =3D 12; > > > $object =3D (new \ReflectionClass('SomeClass'))->newInstanceWithoutConstr= uctor(); > > > (\Closure::bind( > function (SomeClass $object) ($bar > $object->foo =3D $bar; > }, > null, > SomeClass::class > ))($object); > > ?> > > I know this is a weird stuff to do I wouldn't advise to others myself, bu= t > some hydration libraries such as ocramius/generated-hydrator do leverage > this mechanism to hydrate objects, and I sometime do it myself in busines= s > code, sporadically, to hydrate objects from database without needing to > define a constructor for those value objects. > Yes, this is supported. What matters is the scope from which the initialization occurs. If you rebind a closure to the scope of the class, then you can perform any operations that would be legal inside that class, including access to private properties and initialization of readonly properties. Regards, Nikita --00000000000008365505c401f951--