Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127980 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 A1C001A00BC for ; Wed, 9 Jul 2025 17:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752083820; bh=/N+cG9J60JmHvfiTpdkM9kV2wJ/aKFbQIRs3zAnJIQE=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=WV4T6zaRN8ngcjBFyg7uwu7UiEGKEC48hVlTDOZKzFL1UbUOWJ5W9UB9ahZXaIv7q afC/PvVKXoDreDoA+hjyfeE+tbPx7wD1+aaGCETAMt2um0Z/omJ6VJcuNI0DZdoAgp Y7Ov1OLjC6wv0IbK4RT2FII080RCMvO1QTPw1qwKE7NGj7MKtG/MLRLhvotA+K7YgZ Rvd9+NYrZ9TB8ZPkalMdPl2jp63iTIZmMzqnP+sXYbidey5y+hZ6u8045cKh/buIxP RXkBZO6rA5FArV3p7I9DlkdpB/1p2soZubG0GtMN2yei+AxEL2xC9hpDHcU/N4WeDd aZxkWPWzEVe9Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5AD1C1801EA for ; Wed, 9 Jul 2025 17:56:59 +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=-0.4 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, 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 mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 ; Wed, 9 Jul 2025 17:56:59 +0000 (UTC) Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-453066fad06so835155e9.2 for ; Wed, 09 Jul 2025 10:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752083928; x=1752688728; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=L5sOzTqLiB2RNMcpEJRNNtharWKGoDt2FxhFCsnQefg=; b=T9Q1lgnWhfWQFXEK3BzfR4KuAsLg7olzl0Ohvg5nPVH3HX6DEmT+eV19u4oTAJtw8T dKKrswMC5cwHfvQyMNtU1iS1NHjG4ql/D5uQsuqkoMKVC7EXZpI8uJotKovb4VMqfG/Z nN0ygLbzDoFJ+7TKHpjHmZy34AxTtA/87gswmQxFRP6bbwT+qavIG9hfyRiTDFfOudbe Z8GqM8URTrZoEmlhGxxg6/kb/TAUB+ijXELuwzGK7nCG127o1x96aLqXUvgep5EFwuQB e5B0N3nI7w93cAzaJheNDrmzzGZujj6EoDbsM3RB2JDnuMp04uoGNRKvad/os//kE32t 5ekA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752083928; x=1752688728; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L5sOzTqLiB2RNMcpEJRNNtharWKGoDt2FxhFCsnQefg=; b=JA9gX49vRHUtZHkZVxtErk+undVyJAzr+6TDo+z2T22qCSIlrXbmEaRppkiyR9TIOh hTlA0XCGt3EncU/LbM0uWxGBYgHiYuR3Bm8BUvxwMTVw+GejlQvfWycn/5hduzi/BHO9 45tyJfZ0Y7Q7+64MXCz6RNT3yLEke2jYOe18VT2OiDFIpm9uHs4C8XWZmRWOqcGDRYIe RGiAEtf2fjGdvLt7ar6vFrsB0Fe4NfZMz0naPI6WZmDZMYj9vYbHpbwxr7fu9pdJx1Yb FgnkLNi9xBJabvNmde2+VscEC/cSeLaNTeHJO2JoUHejM/9471U3z/fKDU9hBBsWttW5 AcGA== X-Forwarded-Encrypted: i=1; AJvYcCVHaIDFMNvEEXjZOka/STjpEnx35VuHZgkZt83GLQwzj97U1hIf9RtOtzdJUGpTbYaF5LnYviQEgEI=@lists.php.net X-Gm-Message-State: AOJu0Yw13Cpwv3wyr13s3O2g9q8sEzjhlQ7bg5icC3kfWr9bLCBmK44W qEjsjIH4VZ/APs6s2cm3qqID045YciV7vySnTt5veiDhbIMrDgtPIiBP X-Gm-Gg: ASbGncsgxsaH4dTORFuThJ1pzwYvkiQYxvO4LM6TBDOdwGdly5Tqgt5G+jgrCjQmRuE Xy3M+rXa+1855gNCLUBM9U09XhSsKYGnf3+3jxynvlxnPDDRhJ/UQQvMkS5hgCrI4QIqAGZXITS 8VDEf6KGaKMdKtMOXbi71j6Txu0nRkoMVH28eYKrPicD5mbWgVkdRIxHvPa4X0rSNvj5XrHrksf nAXJ3he9u8LZa8/k4Ay/mrbACzLu+MbL0ZFq/XwKEIuAzOPd97USi4aSfVAcFt+CGS007WqczLi qVmolBRcL1GhBnmSfKx8fLzaKCJYLeaeNm7IHH5ojc6vB+nsHWnwdSfmQuTeUYwz/DBzYCvc8zY LI4k/6k7Vlw== X-Google-Smtp-Source: AGHT+IFsEA3vg1zJuOSt0eeYWEXnMLVrls3irBiwQtGufZw0IXAVn1GWC45tSThVwdTNgktAkn9obg== X-Received: by 2002:a05:600c:3145:b0:43b:ca39:6c75 with SMTP id 5b1f17b1804b1-454d536c9bfmr40874085e9.16.1752083927459; Wed, 09 Jul 2025 10:58:47 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454d508c83dsm34852515e9.34.2025.07.09.10.58.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jul 2025 10:58:47 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_20760001-4532-4461-9C21-8FE1F1751129" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PHP-DEV] [RFC] Readonly property hooks Date: Wed, 9 Jul 2025 19:58:36 +0200 In-Reply-To: Cc: Nicolas Grekas , Larry Garfield , php internals To: Nick References: <1e8634d7-ac1a-4025-b4e2-1948aabf5251@app.fastmail.com> <46857A6D-5EAF-44AF-A2DE-9B40AF8DE8C8@gmail.com> X-Mailer: Apple Mail (2.3826.600.51.1.1) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_20760001-4532-4461-9C21-8FE1F1751129 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 9 juil. 2025 =C3=A0 15:17, Nick a =C3=A9crit : >=20 > Hey Claude, >=20 >=20 > I hear you, but I still struggle to fully grasp the issue. It=E2=80=99s = genuinely hard for me to come up with a real-world example that actually = makes sense. > Everything I=E2=80=99ve seen so far, including the RFC example and = what I tried myself (I gave it an honest shot), feels either very = theoretical or entirely intentional, and thus perfectly logical in its = outcome. >=20 > In one of your previous mails you brought up an example that requires = calling a class method (read: intentionally changing class state), which = would result in a non-consistent value being returned when calling the = same property more than once. I get it. But what if the user wants = exactly that in their `readonly` class? Yes, it=E2=80=99s mostly theoretical, but it is good to base language = design on sound theory. But here is a potential practical issue. A random user wants to extend a = class from a third-party library, but they are annoyed that a given = property is readonly. Now, using a get hook, it is trivial for them to = cheat and to work around what it perceives as an undue limitation, not = realising that it may break assumptions made elsewhere in the library. = =E2=80=94 Indeed, I don=E2=80=99t trust users and want to protect them = against themselves. >=20 > That said I did address your concern here (actual RFC PR branch = against alternative; PoC): > = https://github.com/NickSdot/php-php-src/compare/allow-readonly-hooks...Nic= kSdot:php-php-src:readonly-hooks-strict >=20 > Larry and I agree that we don=E2=80=99t want this complexity in the = current RFC. > Perhaps this is something for a separate `init` hook RFC? I think indeed that it is not worth making the current proposal more = complex, but rather considering whether implementing an init hook = instead is a reasonable alternative. Also there is another issue with the use of get hook for lazy = initialisation (although not specific to readonly): The `??=3D` pattern = breaks if the property is nullable and you initialise it to `null`. It = is in fact cumbersome to distinguish between an uninitialised property = and a property initialised with null. =E2=80=94Claude= --Apple-Mail=_20760001-4532-4461-9C21-8FE1F1751129 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 9 juil. 2025 =C3=A0 15:17, Nick = <php@nicksdot.dev> a =C3=A9crit :

Hey Claude,


I hear you, but I still = struggle to fully grasp the issue. It=E2=80=99s genuinely hard for me to = come up with a real-world example that actually makes = sense.
Everything I=E2=80=99ve seen so far, including the RFC = example and what I tried myself (I gave it an honest shot), feels either = very theoretical or entirely intentional, and thus perfectly logical in = its outcome.

In one of your previous mails you = brought up an example that requires calling a class method (read: = intentionally changing class state), which  would result in a = non-consistent value being returned when calling the same property more = than once. I get it. But what if the user wants exactly that in their = `readonly` = class?

Yes, = it=E2=80=99s mostly theoretical, but it is good to base language design = on sound theory.

But here is a potential = practical issue. A random user wants to extend a class from a = third-party library, but they are annoyed that a given property is = readonly. Now, using a get hook, it is trivial for them to cheat and to = work around what it perceives as an undue limitation, not realising that = it may break assumptions made elsewhere in the library.  =E2=80=94 = Indeed, I don=E2=80=99t trust users and want to protect them against = themselves.


That said = I did address your concern here (actual RFC PR branch = against alternative; PoC):

Larry and I agree that we = don=E2=80=99t want this complexity in the current RFC.
Perhaps = this is something for a separate `init` hook = RFC?

I think = indeed that it is not worth making the current proposal more complex, = but rather considering whether implementing an init hook instead is a = reasonable alternative.

Also there is another issue = with the use of get hook for lazy initialisation (although not specific = to readonly): The `??=3D` pattern breaks if the property is nullable and = you initialise it to `null`. It is in fact cumbersome to distinguish = between an uninitialised property and a property initialised with = null.

=E2=80=94Claude
= --Apple-Mail=_20760001-4532-4461-9C21-8FE1F1751129--