Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127605 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 3A01B1A00BC for ; Thu, 5 Jun 2025 06:05:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749103413; bh=J7yko6oF1BUT/CwEEXO3dVTk6YeGXbLy2/md1TaGqtc=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=cv7vC+l/yCQucnXflfaIMW8Fr2GwHeJ9FIXmMqQEdICNO5PxB6YphgyspyIdWJ2Yd jxfdY7ePdcBZ7PQS4GjtYRpGVfmrcYW4YmQ5TlUJwpXgS/Ugc+gxElGiAWE8tQPfRV Er0p394MlF819Fc3O+UoCkvSbgfYOaY/w2bTwKieeBVaCmHC4yXG7gOcqKLVHODkcI ASVy8Vxv5Xhpvj1Y5DXRk8SLQt60DDlmKiy3QTBPgtnHv3k9ytZHQ4H5B6/JS8ZW19 m041z+RlyOrwZhsgKhuFjBnhmaEjJBOEZvsip+RJRXO2FatHtVwyEMZAU0BAcO4J4m 0x+tpZ4lz1EQA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D8AEB180034 for ; Thu, 5 Jun 2025 06:03:31 +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 ; Thu, 5 Jun 2025 06:03:31 +0000 (UTC) Received: from avril.gn2.hosting (localhost [127.0.0.1]) by avril.gn2.hosting (Postfix) with ESMTP id 12CEB1C40C16; Thu, 5 Jun 2025 08:05:33 +0200 (CEST) Received: from smtpclient.apple (unknown [113.210.105.166]) by avril.gn2.hosting (Postfix) with ESMTPSA id B68551C40840; Thu, 5 Jun 2025 08:05:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nicksdot.dev; s=default; t=1749103532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nw0g8fLaVelLfcGaYQPyZzm4FzMJdmIBZ9gHfmn5LvE=; b=Iyq/8tk6A0TZgKDy9Z2qI1mnlrDZqzX85rYTD6Cu2wutYOCt+oXTyPunkx2nLoor7swHo7 AY/rP84ZCxy2vCWxXTKft26CP9FZcSshXIKz24lot2seQDisWdzL1yL0hvBjNSgKmQl9bB yAYzwJVWzeWKxv5mAIpBQVDN631veXljzGTdbjXqczBQfrRtlZhPop+NajboQSROScYftT SHTxevTAlL8nGCjlfub5oKeghAQFlE8PP2RbSZI/nGXpq7xFna31nw8nadWhYwLOcibbDH aMvi9LS3+W4EcKAlLD1CLOua8XmfpKVwG1eHRyn4PJDdJFkdkpe2/OQuGp7QYg== Authentication-Results: avril.gn2.hosting; auth=pass smtp.auth=php@nicksdot.dev smtp.mailfrom=php@nicksdot.dev Content-Type: text/plain; charset=utf-8 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 In-Reply-To: <1c0df916e4cfbc746b5dddf935d165a9@bastelstu.be> Date: Thu, 5 Jun 2025 14:04:50 +0800 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <28F14D0F-8483-418D-85D1-660564A4EAE2@nicksdot.dev> <26AA81AF-1610-494D-A811-10F7B282CBD4@nicksdot.dev> <1c0df916e4cfbc746b5dddf935d165a9@bastelstu.be> To: =?utf-8?Q?Tim_D=C3=BCsterhus?= 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]; FROM_HAS_DN(0.00)[]; NEURAL_HAM(-0.00)[-0.996]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:9534, ipnet:113.210.105.0/24, country:MY]; RCVD_COUNT_ZERO(0.00)[0]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[nicksdot.dev:s=default]; SURBL_MULTI_FAIL(0.00)[nicksdot.dev:server fail,bastelstu.be:server fail,3v4l.org:server fail,smtpclient.apple:server fail] From: php@nicksdot.dev (Nick) Hey Tim, > On 4. Jun 2025, at 21:09, Tim D=C3=BCsterhus wrote: >=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. I added tests for this. The behaviour you expect seems confirmed.=20 >=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. Added = Zend/tests/property_hooks/readonly_property_backed_inheritance_3.phpt Personally, I=E2=80=99d argue nothing unexpected happens here and = everything is fair game. If we overwrite parents from a child it will naturally result in a = changed get hook result. This, however, does not mean the actual class state has changed. Opinions? >> 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 You are right. I edited the tests accordingly. =E2=80=94 Cheers, Nick=