Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114735 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64969 invoked from network); 5 Jun 2021 09:40:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jun 2021 09:40:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 526B71804DA for ; Sat, 5 Jun 2021 02:54:01 -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-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) (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:54:00 -0700 (PDT) Received: by mail-il1-f171.google.com with SMTP id z1so11295559ils.0 for ; Sat, 05 Jun 2021 02:54:00 -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=DoVBUADPEv6TzyOsw73YbHPM7jjdzHfCBRnMc0nsUG0=; b=Hg8mKyr5NcR6kcdWqyd3iMVfmYrzf/og2t9+D4oXhPdGQGnHXsUP4/KaDItG9rwqaC Q7BtrTU4tR2RPN8ZKfOmet/AJACM7n5OBl+kBYw0RTnK2BUWeGi+dY3mJZaNCD6QZ5UO qIPlav4xwYpZjEB7C1x1ZcLBYV77DQoVNTfnSL4VFx90uzNswxc3aTwhdXemz2WXSZSb +EEuFeBzer42leeKzjSC58AYAi9QqR70PlcgzNNSeXTxwvZVerBYPtbQ2/O71M/cVmLI ZfElH4PAf+m9F1qNvofme4pJDJH/EQySws9pSdTtv1jm6ehmQYdimuQQwm8UM103f/jY 5hGw== 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=DoVBUADPEv6TzyOsw73YbHPM7jjdzHfCBRnMc0nsUG0=; b=Wgvf7PIa7Hw+O+MNCpkcLN703r2wwKWMBy0Xa4a3EbmGIKTJOqeaFffg/088zU88Lh 7nURiyFg6x64bKHQ7M3nE+WwiEMyNUGDlz1ahHsVUjw7Rxd6z1f2FrOWpiEpKz+Qhuc7 ///bWQ0UmLJf6AjHNxbTIOKv5rtH5qJksrhdrtnhqDGO57bAeBqFQEfytM6KJcjTlvlJ nj5Q+clA52zVUwLkN+J8pT+hKc2HQK1dGyRJzzqalu0mnIe29gNFMuQyY6GhBP3/d8A9 EVj1CY5XJInQYj4JeCCVH3u1uL434QtBd3WcVfCZwRN2BmkdRZ+5pbfS6cNqZcuhg4KD s0+Q== X-Gm-Message-State: AOAM530pstvtLnAIUZZlmCDLMN/uwrf4jpodayADyF2b8pE8F5muBf7v X1E59b5rtR/Y5i8kTnHYJcnLldIUTaIun31Xyb0= X-Google-Smtp-Source: ABdhPJzXz1BFTE0Fc7cC3CIrxkmnC18GW0eYUWu4nxFhIaAhB0qeK+Z5SX88cnAvukEdaXSRtgvSaPETDNKLPl+kvrQ= X-Received: by 2002:a05:6e02:931:: with SMTP id o17mr7143295ilt.242.1622886838598; Sat, 05 Jun 2021 02:53:58 -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 11:53:47 +0200 Message-ID: To: Pierre Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="0000000000008681da05c401c99c" Subject: Re: [PHP-DEV] [RFC] Readonly properties From: deleugyn@gmail.com (Deleu) --0000000000008681da05c401c99c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jun 5, 2021, 11:47 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.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 a= nd > > 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: > > > class SomeClass > { > public readonly int $foo; > } > > $bar =3D 12; > > > $object =3D (new > \ReflectionClass('SomeClass'))->newInstanceWithoutConstructor(); > > > (\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, > 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 ? > > > class SomeClass > { > public readonly int $foo; > } > > $bar =3D 12; > > $object =3D { > foo: $bar, > }; > > ?> > > 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 > Sounds like a revelant subject to be raised, indeed. But I honestly hope that this awkward hack will not prevent us from getting read-only attributes. > --0000000000008681da05c401c99c--