Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129990 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 312231A00BC for ; Tue, 3 Feb 2026 09:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1770110565; bh=Z+oTK3ZtaLYe/ASZFs42RMew4e7MJ8XsdwvrCUTkC/I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=HuwdqbSfpNoUMlQCfZtpRkClezUzyk8vo4wykU+z8BjQgEVYQi844WTYkhviFC+ye qlbYVKP19lHvnOSyKarY6ayrQe5hwPMez/jrWFlxednEFcp0CXj1NXUTw8qNbIgiUP k5RnE0BnUorfa8PfHhoaXjgvVCuDrnNGPNfgg2/FAgsnJPOI27EF2Be0gyVWlHxwiX w0cIMD8gyF4CKAuVszqw19nIEOJjWh1hHHCUW0z5BCSNfXiPFzS9K/qKj9Qc3DKtkK D+9ccash80506YyyAZvC1EJ0ebflhJodVeEe4Giohc5Ket9QkzAZPuGXYWIHouVWVy GOYwCbsf2GakQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5834E180742 for ; Tue, 3 Feb 2026 09:22:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_FROM,FREEMAIL_REPLY,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 3 Feb 2026 09:22:41 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-5036d7d14easo55486761cf.1 for ; Tue, 03 Feb 2026 01:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770110555; cv=none; d=google.com; s=arc-20240605; b=cNxIIdalnwq+8uQLLz5fgnS0K5sXAUtLZX9Yilc+nXOH8+UiPHKJI2co/VVThZto0v +uBTTXUgKBjl18FBi1T3gITq7nX5LLjoQp2AtISXhAkCtAF6ciO1vELTYnN7qRTeVxpv duxuNc3wEwlq5yXcvr3ho0UUxexWfe94Ttl0I6MgEPkG7C1N8lUERdGXAsxtltfzCrkL Kkh+cbXIlHG3OBDNaKtv7PT/TyKXsgeAZWXaKiMFeMQSkmLWMQ5d2eowH6XIwafll/7H 6iACrLFtpZeV0h6kcpDO5EdAgn+Krg9hhTn8zuz5xf9HSMNmsX1ML5CKC45vyLUaGeUr hMzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=Z+oTK3ZtaLYe/ASZFs42RMew4e7MJ8XsdwvrCUTkC/I=; fh=NauCm4jsxCwrDUWKopy7EgFmshK/3zuubIFdTiA9vLI=; b=L41mBBavFCnM0dZHlo564yukYuJESWYk+c7OetVGlh9ChogkMCBiMW6SAUYMBYDfnI tbM6KhGC0ScDgECJZUuN2QvUrJKn6ED5b+LC12Gdc/c7LapuX4OQybSQ02fIdbWqcGkr 9z/IEM0Pyedb5Iq57I40El8BS8i9L1JI55iOP0Csb8PJ4kc+5kJ4SauJ1P5kxYw5zKdm T24JGSIH6ibbD5v33oYFwQMDwTxWKRw7QSvzzHVN3llJwh7cg6jxEjGF2k8bkYb3AFKM G8gtB/f/NMqsMHjULGBoQ839ECnKULyDiRYVfVGzgpxmtiOZq8omSgI7CMO6roOO79ry aXKQ==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770110555; x=1770715355; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Z+oTK3ZtaLYe/ASZFs42RMew4e7MJ8XsdwvrCUTkC/I=; b=FJt8g31nqfUVEo7khl5T/vmJIAfCN5CDGCSCTJ5G90puXsFtlxNXiu5GVUdD/e1EB+ 2NN3knj5ct8DbI3my5MCuU2h/9m5j70SgwpgIQnRd3rzUbl+hF4mNEguM5I3qSbIdmiG YPOZSD+3KLz/7iEiu6bkjKGQqoOLA1IUj682oRMTIyFu1v8Csj7oXd6cfjpwn0vLtyyn Q3Kc+5KDaMXaFiadEyD7W2kA3vbbbmMKd5nrURcR/ZPYvYiujykpGVKwTYGMIXx6aqHU O3TvnO8k1bvMN7yPlv7htb0/2KSmiTixqQvEYwwLXja08bm8hxeOjwQMcnAHbn4UsflV GGlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770110555; x=1770715355; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Z+oTK3ZtaLYe/ASZFs42RMew4e7MJ8XsdwvrCUTkC/I=; b=b5m23zwF6cCfYLzXXATRg5TVC7m/Kd5M112XMRq1ODMiXwZ8oqDRKgYKV0BwQdJL81 SCXaesvKpheD1lFgLxDSieHgNahnzBuWr55BHtIYkvwpePRZBFP+iHX7oV36aICwdKZ2 y/lvatvCygXpjgxCI+dgMXfzvA+ZgzB5NPaygg74k1zLKfLaEoqblwEb54vRr9JEmCAJ IxpBvkSB+nceqW/gbRDFOMD/fiRZjVX38Lg1StNcxuY9jKZ/dCw11N1I1deQ16s7/u8D S5AroANfXnQmPvFh5DeW5EgCSuLfQ57aZagrfTs3EgtQR2rOacinrchj5kW1DXRKyX1N M3kA== X-Gm-Message-State: AOJu0YzPqfy+Ya4tDmen+IfatnlBCSzDi7YuVSMBlABnTgR1rV3T1zYN wBPPKXJ1QZm+Se6sCeycdmAtOJn+F4K74NWsHRDsSzet3B5SV67iHO4Femr8eXiHKTTYvNnt0op +pDm+NQY3Gy/6M2OY70QA+zadgSxbu9s= X-Gm-Gg: AZuq6aI4Jmlv/FYO+FnTU9aZB+N0gVwXQkZPctiEV5lGpml7gvvKZgMSnIFctg0Bd1T dh36V0jobE0MO4dAQHK9bllhQ7l9wkBzHbqrWTcSVvQRUnT8kZlaidVP46CAEPjH40W2j67AX/2 ayxmFOrnvZf/ABaCANr3T1Ic8L+MqS9ahu39ZcHJLYVQ6Gq28SAC+YaNoxpFsH76pcnPJYQDSzD TrEdyzNKVwL5taIe+JdVkyQnFczs0583km9T+kqHwFWEsfkFnRsxrXhTV6f4yRx66eXsFRMAmZT KnWvVzbTWjTzGfzOzWtP9jYNAA0RzI0SjDycasHG/Nbb+s4jx2xKYOba X-Received: by 2002:a05:622a:14a:b0:503:2b0b:ebee with SMTP id d75a77b69052e-505d2023e19mr171791371cf.0.1770110555012; Tue, 03 Feb 2026 01:22:35 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <4b74f9a1-96d2-4104-abdd-fe56c5e7016c@app.fastmail.com> <585bfc82-a522-43ec-be42-b8945952fe8b@app.fastmail.com> In-Reply-To: <585bfc82-a522-43ec-be42-b8945952fe8b@app.fastmail.com> Date: Tue, 3 Feb 2026 10:22:24 +0100 X-Gm-Features: AZwV_Qj1ozox2zbWL149t4oQGXZ98RN25lSqJyrdnPWNjZ5a497Ie_iK9vTnoPM Message-ID: Subject: Re: [PHP-DEV] [RFC] Allow Reassignment of Promoted Readonly Properties in Constructor To: Rob Landers Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000d8424f0649e7fada" From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000d8424f0649e7fada Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le mar. 3 f=C3=A9vr. 2026 =C3=A0 10:00, Rob Landers a = =C3=A9crit : > On Tue, Feb 3, 2026, at 09:56, Nicolas Grekas wrote: > > Hi Rob, > > Le mar. 3 f=C3=A9vr. 2026 =C3=A0 09:50, Rob Landers a= =C3=A9crit : > > > On Mon, Feb 2, 2026, at 22:14, Nicolas Grekas wrote: > > Hi Marco, > > Le lun. 2 f=C3=A9vr. 2026 =C3=A0 11:54, Marco Pivetta a =C3=A9crit : > > Hey Nicolas, > > > On Thu, 22 Jan 2026 at 16:34, Nicolas Grekas > wrote: > > Dear all, > > Here is a new RFC for you to consider: > https://wiki.php.net/rfc/promoted_readonly_constructor_reassign > > > > What happens if one calls `$obj->__construct(1, 2, 3)` (on an already > instantiated `$obj`) in the context of this patch? > > > Thanks for asking, I didn't think about this. This made me also think > about ReflectionClass::newInstanceWithoutConstructor(). > I clarified this in the RFC, see "Direct __construct() Calls Cannot Bypas= s > Readonly" and "Reflection: Objects Created Without Constructor". > Patch and PR updated also if anyone wants to run some code where this RFC > can be played with. > > Cheers, > Nicolas > > > Hi Nicolas, > > Under "Child Classes Can Reassign Parent Properties": this feels like a > major footgun. Calling parent::__construct() won't allow a reset (per the > rules of calling a constructor directly); which would completely break > inheritance... but then in the examples it says that calling a constructo= r > directly can reset it -- but you can't? > > This feels really inconsistent to me. > > =E2=80=94 Rob > > > Yes, the text was ambiguous. The implementation allows > parent::__construct() during the initial construction (normal inheritance= ), > and only blocks explicit __construct() calls after construction completed= . > I=E2=80=99ve clarified this in the RFC. > > Nicolas > > > Will this result in a catchable error? I assume so, so a valid pattern > during inheritance might be to put these in a try/catch so children can s= et > them first? > > FWIW, in my Records RFC, properties were fully mutable during constructio= n > for exactly this reason. > > The existing behavior is preserved: if a reassignment fails, it throws a catchable Error. The implicit CPP assignment in a parent constructor happens before the parent body, so a child cannot "set first" and then call ''parent::__construct()'' to avoid it; a try/catch in the parent cannot intercept it. But a try/catch in the child can catch of course. Does that answer your question? --000000000000d8424f0649e7fada Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Le=C2=A0mar. 3 = f=C3=A9vr. 2026 =C3=A0=C2=A010:00, Rob Landers <rob@bottled.codes> a = =C3=A9crit=C2=A0:
Hi Rob,

Le=C2= =A0mar. 3 f=C3=A9vr. 2026 =C3=A0=C2=A009:50, Rob Landers <rob@bottled.co= des> a =C3=A9crit=C2=A0:
On Mon, Feb 2, 2026, at 22:14, Nicolas Grekas wrote:
Hi Marco,

Le=C2=A0lun. 2 f=C3=A9vr. 2026 =C3=A0=C2=A011:54, Marco P= ivetta <ocramius= @gmail.com> a =C3=A9crit=C2=A0:
Hey Nicolas,

=

On Thu, 22 Jan 2026 at 16:34, Nicolas = Grekas <nicolas.grekas+php@gmail.com> wrote:
Dear all,

Here is a=C2= =A0new RFC for you to consider:


What happens if one calls `$obj-= >__construct(1, 2, 3)` (on an already instantiated `$obj`) in the contex= t of this patch?

Th= anks for asking, I didn't think about this. This made me also think abo= ut ReflectionClass::newInstanceWithoutConstructor().
I clarified = this in the RFC, see "Direct __construct() Calls Cannot Bypass Readonl= y" and "Reflection: Objects Created Without Constructor".
Patch and PR updated also if anyone wants to run some code where th= is RFC can be played with.

Cheers,
Nicol= as

Hi Nicolas,
=
Under "Child Classes Can Reassign Parent Properties&quo= t;: this feels like a major footgun. Calling parent::__construct() won'= t allow a reset (per the rules of calling a constructor directly); which wo= uld completely break inheritance... but then in the examples it says that c= alling a constructor directly can reset it -- but you can't?
=
This feels really inconsistent to me.

=E2=80= =94 Rob

Yes, the text was ambig= uous. The implementation allows parent::__construct() during the initial co= nstruction (normal inheritance), and only blocks explicit __construct() cal= ls after construction completed. I=E2=80=99ve clarified this in the RFC.

Nicolas

Will this result in a catchable error? I assume so, so a valid patter= n during inheritance might be to put these in a try/catch so children can s= et them first?

FWIW, in my Records RFC, properties= were fully mutable during construction for exactly this reason.=C2=A0

<= /blockquote>

The existing behavior is preserved: if a re= assignment fails, it throws a catchable Error. The implicit CPP assignment = in a parent constructor happens before the parent body, so a child cannot &= quot;set first" and then call ''parent::__construct()''= ; to avoid it; a try/catch in the parent cannot intercept it. But a try/cat= ch in the child can catch of course.

Does that ans= wer your question?
--000000000000d8424f0649e7fada--