Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127585 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 2C8C81A00BC for ; Wed, 4 Jun 2025 13:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749044239; bh=imJVqvn3mB2gTvip5bRbf+BYW3tApp7oEBr3ftyBaak=; h=From:Subject:Date:References:To:In-Reply-To:From; b=BdZoxQYuSm1X8ZD7s+Q4HldN4994A8k9B1lLzJjHPJTim1wR6KXlZzddXXEOKcEbv XE34fzSuLWZLwsJXMVQPUw8jjMZ72RIUHyV8EIntYIGySqvyEoSNDrwMhvmGqogYGP Q0fX55oFkXO6TGYpng0joQZfDDc/6H4BziX+t7xgOu5/Bj3tyshlM00idiXEaUpqWz NaMiEDnMX00C3CHSCnlMeN7pANWZyEBtAM87q9mxUxHoRnQGZXQJIH9Es9abC2cx6w Gg+oPoq/WTFLMkBosH2fNHSVSk4CW7Ax8y8NYzVC/3Yu6/E+Mkefi06ZCZn0b3MFN1 4zWpgOxlXzgAg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BC2EC180547 for ; Wed, 4 Jun 2025 13:37: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=3.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_SBL_CSS, 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 avril.gn2.hosting (avril.gn2.hosting [84.19.162.247]) (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, 4 Jun 2025 13:37:17 +0000 (UTC) Received: from avril.gn2.hosting (localhost [127.0.0.1]) by avril.gn2.hosting (Postfix) with ESMTP id 81D2D1C40C16 for ; Wed, 4 Jun 2025 15:39:19 +0200 (CEST) Received: from smtpclient.apple (unknown [113.210.105.166]) by avril.gn2.hosting (Postfix) with ESMTPSA id F01A51C40171 for ; Wed, 4 Jun 2025 15:39:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nicksdot.dev; s=default; t=1749044359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=He2whiJOWFmr19TmBlV+nlLX4aUuoLbcDJwavitt9lQ=; b=QMeDmTgF1EDtpAd5LwGVpqDOR+W6vP1tDG53xwIHmKc4JIRhWrXXEffxRYcShtLgYU5eNt Mf1SMNgSxgZodZ82B01oSPr9XFRfRonXkCxovP9AGKBFwACSa+U57Z0ppeLd61Ucdvhrfk 3fNqVxkgHFr6A8WktjtpgHVVNRxSuF9NHTYBtOvpsQzN/ttQZznsmEzEH5O7cPS0Ceocvw 2/1nXiLi2InaASIwOwinDDMhNh8W+3ckSqbys6jymURodBcG7EoV5kakI4bR3Gp14dhl+L zGC0Q34HywjUPbkacV2hmuhjAqc4mka/Eb5osgk8KgN6PIBc32CZSmbRlPUNVg== Authentication-Results: avril.gn2.hosting; auth=pass smtp.auth=php@nicksdot.dev smtp.mailfrom=php@nicksdot.dev Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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] Allow hooks in `readonly` promoted properties Date: Wed, 4 Jun 2025 21:39:01 +0800 References: <28F14D0F-8483-418D-85D1-660564A4EAE2@nicksdot.dev> <26AA81AF-1610-494D-A811-10F7B282CBD4@nicksdot.dev> <1c0df916e4cfbc746b5dddf935d165a9@bastelstu.be> To: internals@lists.php.net In-Reply-To: <1c0df916e4cfbc746b5dddf935d165a9@bastelstu.be> Message-ID: X-Mailer: Apple Mail (2.3826.600.51.1.1) X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.60 / 15.00]; BAYES_HAM(-3.00)[100.00%]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM(-0.00)[-0.995]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; ASN(0.00)[asn:9534, ipnet:113.210.105.0/24, country:MY]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[nicksdot.dev:s=default]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCPT_COUNT_ONE(0.00)[1] From: php@nicksdot.dev (Nick) Hey Tim, > On 4. Jun 2025, at 21:09, Tim D=C3=BCsterhus wrote: >=20 > Hi >=20 > Am 2025-06-04 14:19, schrieb Nick: >> Fair. If someone really wants to add random_int(): "well, that = assumption doesn't hold anymore, deal=E2=80=9D from my side. >=20 > Semantically once you involved inheritance it isn't that easy. It is = allowed to override an =E2=80=9Cunhooked=E2=80=9D property with a hooked = property and in the =E2=80=9CReadonly Amendments=E2=80=9D RFC we already = decided that inheriting from a `readonly` class by a non-`readonly` = class should not be valid. >=20 > So if you would be allowed to override a readonly unhooked property = with a hooked property that has a `get` hook that is not a pure = function, you would make the property effectively mutable, which is = something that users of the class can't expect. It violates the history = property of the Liskov substitution principle. >=20 > Making this legal might also inhibit engine optimization. Currently if = you know that a property is readonly you can theoretically optimize: >=20 > if ($object->foo !=3D=3D null) { > do_something($object->foo); > } >=20 > into: >=20 > if (($foo =3D $object->foo) !=3D=3D null) { > do_something($foo); > } >=20 > to avoid reading `$object->foo` twice, which for example would need to = check visibility twice. >=20 >>> I believe at the moment that RFC text is all there is. :-) I don't = know that it's worth opening a discussion without at least a mostly-done = implementation. Also, Ilija is rather busy on other tasks at the = moment, as am I. (Unless someone else wants to jump in to implement it, = which would be fine.) >> People often say =E2=80=9Cyou can just do things=E2=80=9D. So I did, = and tried to contribute the code for your existing RFC text: >> https://github.com/php/php-src/pull/18757 >> Can it really be such a little change? I=E2=80=99d appreciate = feedback from people more experienced than I am. Thanks! >=20 > Your test cases really only scratch the surface of what should be = tested. You are basically just verifying that it compiles. In fact you = are not even testing that reassigning the property is disallowed, = because the test fails due to a visibility error. In fact it appears = that the `readonly` check comes before the visibility check, which would = imply that the `readonly` doesn't have an effect: https://3v4l.org/nqgpL = https://github.com/php/php-src/pull/18757/files#diff-fdc22521b074231ac6de0= df97aeb23a4759ad9b668d3b9ed3fedf8727f5795a4R21 It checks re-assignment, and expects: > Cannot modify protected(set) readonly property Test1::$prop from = global scope It=E2=80=99s tested for readonly props, readonly class and promoted = properties. Correct me, but this is what you are talking about, isn't it? Anything = else you are missing?=