Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127632 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 859311A00BC for ; Mon, 9 Jun 2025 15:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749481360; bh=Wloq3g8YiT10jePEwC8DexiE7HWY2/Lr9ZAjNVqLW6c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Pt/JbKhn6dLY18NgsOhKW1MuhBKRgkyLnwIEFOZOkBdwCsNnPveMNQ58W7zR6lGaF na5pzNcoLmzNLhdtX7oLbkqoWJgnfhOsEYmQXXykwFkkMBgkWuW9aeib8nKzI4Uikk PlDZAudjN1LWI/pRc7GJMetMyBEosHrbTrThGJv+1a/KzpR4Uf0zDIHt8I97juTKfw aW3vOTBQjzaq88g3UW2W8rjvHjwpnz09rg1kjAsexGqVZTW4WQy+zKLOiw/lAF6Sqg +sJbWPEMindppuEEn2vK2RC4kvrMoSN3YpwctW88LSgJHwdDFhwWxR1bdMGMleRzNC gF0CugcDW1uRw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DD6281801DC for ; Mon, 9 Jun 2025 15:02:39 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,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 chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Mon, 9 Jun 2025 15:02:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1749481480; bh=YL5pItPZDDXVy3oJovhEX19bxxYDlcvGxB/Ntco6TYA=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=kSJxazlZkStjcLiJ09KvCjmwMAAT/8Vs4X47N75e6mo16oH0QDTRyUAt0vmmkfENu 39rwUKFcttBvSNfPNkrhNDcm9SW0sowcX7d5EmH6vp7/dBFGzZ9nNbBnuTliQ0ey06 ADaKEVQiMcyQWM6dTu2/6sO8P+cWc4zNIDPBsdZyEJpH5MQuVPL3rkG0sSfOFJubPg euiW7hJJ7ztFSYCGYh7Xz33pAdEHey+ouF928UnpQWbG1aD2U6n2h29y8aml/aH6fC 7HSV3JdBXgv6vyy9ufR0xucn5/e3Q70crdxTWGw5QevCGl0sXaL96m+Lh5WNLKGqA7 AfGUiHeGjUxPg== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 09 Jun 2025 17:04:39 +0200 To: Nick Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Allow hooks in `readonly` promoted properties In-Reply-To: References: <28F14D0F-8483-418D-85D1-660564A4EAE2@nicksdot.dev> <26AA81AF-1610-494D-A811-10F7B282CBD4@nicksdot.dev> <1c0df916e4cfbc746b5dddf935d165a9@bastelstu.be> Message-ID: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-06-05 08:04, schrieb Nick: >> Semantically once you involved inheritance it isn't that easy. It is >> allowed to override an “unhooked” property with a hooked property and >> in the “Readonly Amendments” 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. I think you might have misunderstood me there. I was not specifically discussing the inheritance of readonly and non-readonly classes, but the user’s expectations for the semantics of readonly classes. This paragraph was intended as an introduction for the following paragraphs. To be clear: The tests do not confirm my expected behavior, since I expect a `readonly` property to never change after successfully reading it. But that's something for the official RFC discussion. >> >> 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. >> >> Making this legal might also inhibit engine optimization. Currently if >> you know that a property is readonly you can theoretically optimize: >> >> if ($object->foo !== null) { >> do_something($object->foo); >> } >> >> into: >> >> if (($foo = $object->foo) !== null) { >> do_something($foo); >> } >> >> 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’d 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. I'd argue that the user is not interested in the “actual class state”, but what they can observe from interacting with the class. I'll probably discuss this in more detail in the official RFC discussion thread. Best regards Tim Düsterhus