Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128176 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 6C12E1A00BC for ; Tue, 22 Jul 2025 09:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753176261; bh=uVT/WHBSuh+XhYlXfUdmfE54ikTq8zdmq6QKvdSHzHc=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=myTC6CO0w2anrHPycJGoqod3tb3CTJ5XfjfYpcor7LaxGI25UWKBY4Wele1BjDFpC mQPbFJwa9CYuiimaSkmjYAX5JB8KigKzU5qgG8AAmWZ+jOkLJrZHE2TuNugvbJyTWs XsWsARD7XcaZrCxZmTYGdfjHhcOy2F4zWgewi6SCTk8QtHYxKszT0HiBBfRXYJzUg4 5BjJPd0bOXfp1lKu0ZVGk0aS3uY9kzB75D12ULdlRivBXRSqozHUrywlL1Btr0FzKG yPEI9p9CmBcetkATBc/ThhMShadMllgJN69DYr1u6ek/Eml13Pi43x7xJsj0jBOhmd lK8/x+guKpo2w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3B95B180083 for ; Tue, 22 Jul 2025 09:24: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 fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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, 22 Jul 2025 09:24:16 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id BCEFA14001DD; Tue, 22 Jul 2025 05:26:01 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Tue, 22 Jul 2025 05:26: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=1753176361; x= 1753262761; bh=ZPgi4xvvFHGuSZDyUae0Zj+OIpobSL0lUwdiWQOpKLU=; b=K DyDDrYJXVrWHETM4h8vkaRD4W44GNSu4IhlutHsaATL5VOSIkyXPjoziu5u7Rk2G JYxaWPh67c6U76rYJgAxHFOd0RtBJjqsUsHRRzMdggiAmfMPgqdl9PPxCRHQvJfT XE1HMOBCu657pcw2WKhTz2sxRqqu3BqcazguwvOz6CyQVZDKUWi4aD90y9Gq3UjB nGGmktdPTy7JEyFdsXfnBBRQldeg8l4g/O2ccWJR0v0LY0VUePJazzAxaCWJ4Fyq g3tLTI0eCOkBntpMmzAKsizV67VcIdg6ajRudFgNBEpKcMxEFowFn1Q3Ydyx93Ad bjEoeqQFShroKE1pbkYMg== 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= 1753176361; x=1753262761; bh=ZPgi4xvvFHGuSZDyUae0Zj+OIpobSL0lUwd iWQOpKLU=; b=HJz8idrIdluryd8eP/ru0mtSntMfk9eQIG+RZGF7O4iub62aqmh NmWlgYo1xzcDlwkh/A+CASNCfuCZDJG+3iIFq0pXt+1xbvpuXBQuEbOypcOzflJS wdq6nU+a+7h2Hv+QvGk6RkRRANpF/6WYEi+aihNhky3bQ+X9L3PglqdQg+brKdx5 NEvABNoNyYL8VVNMGSK1Dam3GQOi9pgMcZUNmy1B2oe6KIthAShKnogYk4gzjhIb Lslj2gpiWkhcI9B+8yhPM0IDz1ysJufzZ0ZZs1q0cD1embONt/pmrdbDX+weWNY9 WPp1HVWSb1htyx/16pctqX/5C+nGVCljINw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejgeehgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgr nhguvghrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvg hrnhephfevteevuefhjeeitdehhfevgedvvdfgudejvedukeffhfehvdfgffegvdelfeff necuffhomhgrihhnpeefvheglhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggp rhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegtlhgruhguvg drphgrtghhvgesghhmrghilhdrtghomhdprhgtphhtthhopegvrhhitghtnhhorhhrihhs sehgmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrph hhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 56CA31820074; Tue, 22 Jul 2025 05:26:01 -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: T0d65545c0179fcf6 Date: Tue, 22 Jul 2025 11:25:39 +0200 To: "Claude Pache" Cc: erictnorris@gmail.com, "php internals" Message-ID: <77df950f-894a-41c1-863b-89871522d14c@app.fastmail.com> 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> <5a51401a-450b-46f0-8467-88d31efecb9c@app.fastmail.com> <4567d926-aaed-44a8-9cd6-68e8e12742f4@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Readonly property hooks Content-Type: multipart/alternative; boundary=71feaf58aefe4ab6b2b5c0b0de2b9dbd From: rob@bottled.codes ("Rob Landers") --71feaf58aefe4ab6b2b5c0b0de2b9dbd Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jul 22, 2025, at 11:18, Claude Pache wrote: >=20 >=20 >> Le 22 juil. 2025 =C3=A0 09:43, Rob Landers a =C3=A9= crit : >>=20 >> You can also implement this today, without using readonly: >>=20 >> class Foo { >> public int $bar { >> get =3D> $this->bar; >> set =3D> empty($this->bar) ? $this->bar =3D $value : throw new Lo= gicException("nope"); >> } >> } >>=20 >> https://3v4l.org/2JagR#v8.4.10 >>=20 >=20 > Your code is buggy, because `0` is =E2=80=9Cempty=E2=80=9D: >=20 > https://3v4l.org/iUPvW#v8.4.10 I wrote it over 30s while getting ready to walk out the door for a week = long vacation, so I won=E2=80=99t be entirely surprised if it is wrong. = :) >=20 >> Should I be able to mark this class as readonly? I would think so. >=20 > I don=E2=80=99t think so. >=20 > If you want to *document* the intended invariant, you can put a @reado= nly tag in a phpdoc comment. >=20 > Adding a `readonly` keyword should *enforce* the invariant; the added = value is that it would choke on bugs like the one you wrote just above, = making it debugging much easier. I=E2=80=99m not sure if you meant to, but I feel like you just argued fo= r allowing readonly on hooks so that these kinds of bugs aren=E2=80=99t = accidentally written=E2=80=A6 >=20 >=20 >> The readonly keyword simplified that greatly, however, readonly has b= een neutered compared to regular classes in the last couple of versions.= There are so many edge cases and non-implemented features with them -- = mostly due to this exact argument you are making -- that they're nearly = worthless to actually define immutable value objects in today's PHP. >>=20 >=20 > There are several issues with the readonly feature, mostly because of = the =E2=80=9Cworse-is-better=E2=80=9D philosophy. But we can slowly corr= ect the main issues instead of making them worse. >=20 > =E2=80=94Claude I think this is the main crux of the issue, right? There is one camp tha= t says readonly means immutable and another that says readonly is read-o= nly. These two viewpoints are not compatible despite having a lot of ove= rlap. =E2=80=94 Rob --71feaf58aefe4ab6b2b5c0b0de2b9dbd Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Tue, Jul = 22, 2025, at 11:18, Claude Pache wrote:


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

You can also imple= ment this today, without using readonly:

=
class Foo {
 = ; public int $bar {
    get =3D>= $this->bar;
    set =3D> emp= ty($this->bar) ? $this->bar =3D $value : throw new LogicException(= "nope");
  }
= }

=


Y= our code is buggy, because `0` is =E2=80=9Cempty=E2=80=9D:

I wrote it= over 30s while getting ready to walk out the door for a week long vacat= ion, so I won=E2=80=99t be entirely surprised if it is wrong. :)


Should I be able to mark this= class as readonly? I would think so.

I don=E2=80=99t think so.

If yo= u want to *document* the intended invariant, you can put a @readonly tag= in a phpdoc comment.

Adding a `readonly` keywo= rd should *enforce* the invariant; the added value is that it would chok= e on bugs like the one you wrote just above, making it debugging much ea= sier.

I=E2=80=99m not sure if you = meant to, but I feel like you just argued for allowing readonly on hooks= so that these kinds of bugs aren=E2=80=99t accidentally written=E2=80=A6=



The readonly keyw= ord simplified that greatly, however, readonly has been neutered compare= d to regular classes in the last couple of versions. There are so many e= dge cases and non-implemented features with them -- mostly due to this e= xact argument you are making -- that they're nearly worthless to actuall= y define immutable value objects in today's PHP.


There are several issues with the re= adonly feature, mostly because of the =E2=80=9Cworse-is-better=E2=80=9D = philosophy. But we can slowly correct the main issues instead of making = them worse.

=E2=80=94Claude

I think this is the main crux of the issue, right= ? There is one camp that says readonly means immutable and another that = says readonly is read-only. These two viewpoints are not compatible desp= ite having a lot of overlap.

=E2=80=94 Rob
--71feaf58aefe4ab6b2b5c0b0de2b9dbd--