Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128134 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 B965B1A00BC for ; Sat, 19 Jul 2025 10:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752919880; bh=FA3T42DfMoibMb0n2bCMGdR631EhpynrqJNg2ec8Gkg=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=TP/K7r3vQMT2jhOQoBpKm3iBp61S/uswu6lcHz/hE8C/cMwr7OM6ddHs0VsxsyKqf QjGrtNPsKau1qghnKUYK0UrqgOcSCWWYJAFgv/f0PQqC+6loXi445DDWe+iFWBaa+t eKJYulUaVIHhCdeGDvESsL/PQm/8df0IgO5PUB7YmI1m6UjsnSCY6O46rk76RDUoqX VSzZ7aHnx9hEmO/BYeWPMPa+8GlS+Q9qSiW+frH/JAIByfzf2oITMUH7MCmzXOodJT FogzDVKe+amQtuHrsR2Gltw+EJx/vtOWdGmKwSHeFh5aH/Ol+UvsWYl3ncXiJ6WOvr lpiBuk075qxjA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4D3981805E2 for ; Sat, 19 Jul 2025 10:11:17 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-a3-smtp.messagingengine.com (fout-a3-smtp.messagingengine.com [103.168.172.146]) (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 ; Sat, 19 Jul 2025 10:11:15 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 31CAAEC00D8; Sat, 19 Jul 2025 06:13:01 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Sat, 19 Jul 2025 06:13:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1752919981; x= 1753006381; bh=FA3T42DfMoibMb0n2bCMGdR631EhpynrqJNg2ec8Gkg=; b=Z z/HepYpe19gwyUvWlTvXXHqHR1Smc5aEMSuLXX1JDwI4umNUkTNyLt9RsE9PwIbv phbnnS5aIvXTVULoA19ZCZ7UyJbeYPc+hdHRBqHoxj+NPiK4sgou/IpOhc0XufEj GIDk6iNVr+1cLr0L0bfHHZ+GvyZD8tpqIOz2eUaj2M1VaXe7xhoOf19xnv7uCSaf 5GV0BqxUka+BoxqC3czqx4uLm7DUMtTp2aHA+jmI7cDa7Gxtg4opLn8Wl+IEIdJ1 1Hds+QkiMkASp+HkeagWa2OknbQOlAsB96j7uB3V+puaOd+fk0JC8YzlB0arCrsj tO92jMgrSYFsugtzcDV0w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1752919981; x=1753006381; bh=FA3T42DfMoibMb0n2bCMGdR631EhpynrqJN g2ec8Gkg=; b=XrSTqj86/VZACDzrkdEJUur9R4NC54pC5q8bo7DW5rmWJRJTyfr aXABgGW9WdpWKsdhiRfZ48GapIPvxgbqGvrMLhW1+vkQZO4FfRpuagivqNgw13mA 8upjaP87JbsUcWyp5D76J15bXSbL9LfMk5+ajxPWHTiwweA0yp0Eqz+iQUgzirLc tfZQhvGHXVybGloaCSkOyj6C4iv55V5fJbdMPxolPzULftIshc8XmPx4E9Bd5i7C fWF5JOGSKmPt+dM0ZoTRXBujZ4Z5dyXDhm+27uZ1rSzqhhOnRQ7/7gfjyObOVcM9 r5uaE4vs89qL20sGAXB4st2xKwfEVH0sAdg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdeiiedtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgr nhguvghrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvg hrnhepieeuteehvddvfeejhffgieehleehhedthfefkeejffelgfevvdekudetjeejtddt necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosg essghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtohepthhimhessggrshhtvghlshhtuhdrsggvpdhrtghpthhtoh eplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhrtghpthhtoheptghlrghu uggvrdhprggthhgvsehgmhgrihhlrdgtohhmpdhrtghpthhtohepvghrihgtthhnohhrrh hishesghhmrghilhdrtghomhdprhgtphhtthhopehnihgtohhlrghsrdhgrhgvkhgrshdo phhhphesghhmrghilhdrtghomhdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsth hsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id AF25F1820074; Sat, 19 Jul 2025 06:13:00 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T5f4527d1a0d4de24 Date: Sat, 19 Jul 2025 12:12:40 +0200 To: "Claude Pache" Cc: erictnorris@gmail.com, "Nicolas Grekas" , "Larry Garfield" , =?UTF-8?Q?Tim_D=C3=BCsterhus?= , "php internals" Message-ID: In-Reply-To: References: <378cd8b0-c4a8-4e53-b0bd-e9e4f30a454d@app.fastmail.com> <77128196-8D53-40D6-9BB7-77160AD71ED9@gmail.com> <247034b6-04cf-4f3e-a145-a30171af8c12@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Readonly property hooks Content-Type: multipart/alternative; boundary=9e00dd2bd10e43c8a9ea6401195f3792 From: rob@bottled.codes ("Rob Landers") --9e00dd2bd10e43c8a9ea6401195f3792 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Jul 19, 2025, at 12:09, Claude Pache wrote: >=20 >=20 >> Le 19 juil. 2025 =C3=A0 09:46, Rob Landers a =C3=A9= crit : >>=20 >>=20 >>=20 >> On Sat, Jul 19, 2025, at 03:04, Claude Pache wrote: >>>=20 >>>=20 >>>=20 >>>> Le 19 juil. 2025 =C3=A0 00:41, Rob Landers a =C3= =A9crit : >>>>=20 >>>> The original author (Nikita) suggested that there's nothing in the = original design that precludes accessors -- and highlights languages whe= re there are both and they are doing just fine more than 5 years later. >>>>=20 >>>=20 >>> Hi Rob, >>>=20 >>> It is indeed entirely reasonable to have both readonly properties an= d hooked properties (aka accessors), and today PHP has indeed both of th= em (and even asymmetric visibility on top of that, as a separate feature= contrarily to C#). But it doesn=E2=80=99t mean that it is reasonable fo= r the *same* property to be *both* readonly and hooked, which is the poi= nt that is currently disputed. =E2=80=94 What do the other languages all= ow? Is it possible to define a readonly property with a user-defined get= ter? (Disclaimer: Even if one of them allows such a thing, I=E2=80=99ll = still think that it is a bad idea.) >>>=20 >>> =E2=80=94Claude=20 >>=20 >> Hey Claude, >>=20 >> From what I've seen in other languages, this combination is fairly co= mmon and not inherently poblematic. >>=20 >> - C# allows get hooks with user-defined logic, even in readonly struc= ts. >> - Kotlin uses val with a get() body, which is readonly from the consu= mer's perspective, even though the value is computed. >> - TypeScript allows a get-only accessor which acts readonly. >> - Swift also allows get-only computed accessors/hooks. >=20 > Hi Rob,=20 >=20 > The main problem is that we don=E2=80=99t agree on the meaning of =E2=80= =9Creadonly property=E2=80=9D. >=20 > I=E2=80=99ve check TypeScript: >=20 > * It has getters and setters, which correspond to PHP get/set hooks wi= thout backing store. >=20 > * Separately, it also has a `readonly` modifier that can be applied to= properties; the semantics is that such a property may be initialised ei= ther at declaration or inside the constructor, but cannot be modified af= terwards. That corresponds approximatively to PHP readonly properties. >=20 > * But a =E2=80=9Cget-only accessor=E2=80=9D is not the same thing as a= =E2=80=9Creadonly property=E2=80=9D in the specific sense of =E2=80=9Da= property decorated with the `readonly` modifier=E2=80=9D. Also, you can= not add the readonly modifier to a get accessor. >=20 > =E2=80=94Claude >=20 The error you get when trying to modify the "get-only accessor" is `Erro= r: Cannot assign to 'name' because it is a read-only property` Thus, readonly is implied by the get-only accessor, there's no need to s= pecify it directly. =E2=80=94 Rob --9e00dd2bd10e43c8a9ea6401195f3792 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Sat, Jul 19, 2025, at 12:09, Claude Pache wrote:


Le = 19 juil. 2025 =C3=A0 09:46, Rob Landers <rob@bottled.codes> a =C3=A9= crit :



= On Sat, Jul 19, 2025, at 03:04, Claude Pache wrote:


Le 19 juil. 2025 =C3=A0 00:41, Rob Landers <= rob@bottled.codes> a =C3=A9crit :

The original author (Nikita) suggested that the= re's nothing in the original design that precludes accessors -- and high= lights languages where there are both and they are doing just fine more = than 5 years later.


Hi Rob,

It is indeed entirely reasonable to have both re= adonly properties and hooked properties (aka accessors), and today PHP h= as indeed both of them (and even asymmetric visibility on top of that, a= s a separate feature contrarily to C#). But it doesn=E2=80=99t mean that= it is reasonable for the *same* property to be *both* readonly and hook= ed, which is the point that is currently disputed. =E2=80=94 What do the= other languages allow? Is it possible to define a readonly property wit= h a user-defined getter? (Disclaimer: Even if one of them allows such a = thing, I=E2=80=99ll still think that it is a bad idea.)

=E2=80=94Claude 

Hey Claude,

From what I've seen in other lan= guages, this combination is fairly common and not inherently poblem= atic.

- C# allows get hooks with user-defined l= ogic, even in readonly structs.
- Kotlin uses val with a get()= body, which is readonly from the consumer's perspective, even though th= e value is computed.
- TypeScript allows a get-only accessor w= hich acts readonly.
- Swift also allows get-only computed acce= ssors/hooks.

Hi Rob,&n= bsp;

The main problem is that we don=E2=80=99t = agree on the meaning of =E2=80=9Creadonly property=E2=80=9D.
<= br>
I=E2=80=99ve check TypeScript:

* = It has getters and setters, which correspond to PHP get/set hooks withou= t backing store.

* Separately, it also has a `r= eadonly` modifier that can be applied to properties; the semantics is th= at such a property may be initialised either at declaration or inside th= e constructor, but cannot be modified afterwards. That corresponds appro= ximatively to PHP readonly properties.

* But a = =E2=80=9Cget-only accessor=E2=80=9D is not the same thing as a =E2=80=9C= readonly property=E2=80=9D in the specific sense of =E2=80=9Da property = decorated with the `readonly` modifier=E2=80=9D. Also, you cannot add th= e readonly modifier to a get accessor.

=E2=80=94= Claude


The er= ror you get when trying to modify the "get-only accessor" is `Error: Cannot as= sign to 'name' because it is a read-only property`
=
Thus, readonly is implied by the get-only accessor, there= 's no need to specify it directly.

=E2=80=94 Rob
--9e00dd2bd10e43c8a9ea6401195f3792--