Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114740 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88922 invoked from network); 5 Jun 2021 14:21:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jun 2021 14:21:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A6511804C9 for ; Sat, 5 Jun 2021 07:35:05 -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-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 07:35:04 -0700 (PDT) Received: by mail-lf1-f49.google.com with SMTP id w33so18464091lfu.7 for ; Sat, 05 Jun 2021 07:35:04 -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=d/j5pHcnDBozuOSA9ptnQg80MYlHzbB0z9pLAS9nCFA=; b=kEWQWsF7IpLGgNIFffl2FgQimS8M3bSs7ENxr1Tx+Sjd0mBbI4vL07V8t1uqkn6Pmz NCaYdJN9U+mL3ETdHR++d4Biz5xLoRA9XiMUuU80zi5sDD8w83hxL+fwARB/za3/z0gy PpS6UBfbOnw/kZ1uuq6fq7ExSI86/7M1d56oVcjT2EYBc7NTRaQQQPfiY7LVUTY5AhjI 7cCtrBl6eXR/ugzLcrZDUqpZF7lJ2QlQF2Y/lbdhzGvr7YNkrXOMoxorvyXQME6Wv8nA kUb47lUWjieLSzzRnhKvUd2WEFtkxnMk/k/52sGV7SS4bqui4lTibix8Zn3tDLRig1vr CfHg== 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=d/j5pHcnDBozuOSA9ptnQg80MYlHzbB0z9pLAS9nCFA=; b=Qu777mG2GAIYKesqzBUvf7Y7aiV+2GrB+bxXgWUfj20eAalCJm+rcBRYXidRCjQo+a GyVH87WLuHif+Sslldx2+84GM0knyZTT7InH0XeaSTVJHZS9E4wY55+kkRMb2UZQHwB1 t0YrJfnUYqqUAJbf2pw8QQzO/yjtmliph98UtikM6afTskMzIU4J1rrB4Ket7VhM8lIP X9vkKauXJC7+G8S11cHQUeqpWEtXFAmKmPCZOvZeRnxC06n0uv0iTYCm+Y5kJNSa4Hjg 5sHfbwaNZf3uu1IEod6RnMTh3qJblv5yTW5JPF8rThPqVHHuHh+Vc+9KknyZdTNf3QU7 gWnA== X-Gm-Message-State: AOAM532QoHBsLi1NnJqgqZF6husAK5zbsgjNAjgbhgYxZMsbiQcwMf9B +7t9S0uV75eP4/r6Ezlr8e59FIfPdx30iA50T14TwAGQH/4oig== X-Google-Smtp-Source: ABdhPJwT/bPQp2VfX4gx+eXySrUfrwlvV85MvFdCiEoAO2JVPPX5eHewGXXgBffu/5REsB0Gy1dIN20OSyd2oLbe21k= X-Received: by 2002:a05:6512:3e12:: with SMTP id i18mr6280832lfv.286.1622903700445; Sat, 05 Jun 2021 07:35:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 5 Jun 2021 16:34:44 +0200 Message-ID: To: Benjamin Eberlei Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000091dd2e05c405b63a" Subject: Re: [PHP-DEV] [RFC] Readonly properties From: nikita.ppv@gmail.com (Nikita Popov) --00000000000091dd2e05c405b63a Content-Type: text/plain; charset="UTF-8" On Sat, Jun 5, 2021 at 4:28 PM Benjamin Eberlei wrote: > > > On Fri, Jun 4, 2021 at 5:20 PM Nikita Popov wrote: > >> 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. >> > > I have a question about Reflection support, the RFC states: > > > ReflectionProperty::setValue() can bypass the requirement that > initialization occurs from the scope where the property has been declared. > However, reflection cannot modify a readonly property that has already been > initialized. > > Is there a reason why this is not possible? I am thinking about ORMs or > Deserializers here where a pattern would be: > > class MyDataObject > { > public function __construct( > public readonly $foo > ) {} > } > > $dataObject = $reflectionClass->newInstanceWithoutConstructor(); > $dataObject->getProperty('foo')->setValue($row['value']); > This example is compatible with the proposal. Calling newInstanceWithoutConstructor() leaves the property uninitialized, and you can initialize it through reflection (or closure rebinding) from any scope. Hydration and deserialization only requires the ability to initialize, not to change the value of properties past initialization. Regards, Nikita --00000000000091dd2e05c405b63a--