Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128114 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 76C271A00BC for ; Fri, 18 Jul 2025 15:25:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752852209; bh=vaIEp4JeteNfMiTvXlUPoG4enSW98w1ZpUhe9psQ+i0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=lWrGhOu687aJXoe9vOz7r212e48zDJCZtncqKUP88pmcnULIfLRbXr7kO6RAUumAP 82u1K4w2vKD8VfmsMy98p90enIuh6IlZ5RT50nhw0zsAi6pD1q3bhRQXMloOPQ3KHW cmU5B47OvC+sshPHFjkmaKVv62S5ZCDqH3/FXgxpbzClfyBUylZ5/tYXcGPP9JbdS5 QICaQVDdaxdDdaH4zu8snrQT/toWOgG6Crr61/eYUYjvb/wd2sNIZVmEDRe3uP+i6P oPeRj8dD0+HT6K2iglQ0Qu/YhJACyzHe+LUFL8yswSuZjVfN/BITjAwtU9eGHzjtxL CE3L1IaQfOgzA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 184E4180050 for ; Fri, 18 Jul 2025 15:23:28 +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 ; Fri, 18 Jul 2025 15:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1752852313; bh=VxXUjDTGjbrWG7KMkolzL2AdidyOxBbmdZSOzsBy7T4=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=lTMkhgqXBNCwx1MIbT3tqcVz4OxsXaKhRQE5jYlLU/rS7OAiMGirsTtISAOH7o95+ W+GZiIzJTtbsEDou32bfw1QaSo7ZsytCBXkx67es9ONNlIH5t0gK5AQqhe7NyLTv/m wTQBTb6FTUMasNeCYt5FnufL7lUq2ofI0xOa0cpgHN1IStx5SMjrorIsDvqi30qCH8 tkJfMkeaW65Kv/2NPrh4t28X3YWvU41Bnsv9wR3uXydmmdZSjeM0P3IWD95mpufh1L uv8YQ++c3l9dmopR+2Jz+u7NIxCemQIfgi00NOt8wHMDgClz5n3Pb6cseL4flbxtjG KzbJmVbPo6KWw== Message-ID: <2641b8bc-6337-4b75-a5a3-93dee1b03796@bastelstu.be> Date: Fri, 18 Jul 2025 17:25:12 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Readonly property hooks To: Larry Garfield , php internals References: <1e8634d7-ac1a-4025-b4e2-1948aabf5251@app.fastmail.com> <9D5043B2-1589-4FD5-B289-6E98FB1177BE@nicksdot.dev> <0856c89f-2000-448a-bbbf-c145a8699f6a@app.fastmail.com> Content-Language: en-US In-Reply-To: <0856c89f-2000-448a-bbbf-c145a8699f6a@app.fastmail.com> 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 On 7/14/25 15:38, Larry Garfield wrote: > Thanks, Ilija. You expressed my concerns as well. And yes, in practice, readonly classes over-reaching is the main use case; if you're marking individual properties readonly, then just don't mark the one that has a hook on it (use aviz if needed) and there's no issue. A readonly class is not just a convenience shortcut to mark each individual property as readonly. It has important semantics of its own, because it forces child classes to also be readonly. And even for final classes it communicates to the user that "I won't be adding non-readonly properties to the class". Marking a class as readonly must therefore be a deliberate decision, since it affects the public API of your class and in turn also user expectations. > Perhaps we're thinking about this the wrong way, though? So far we've talked as though readonly makes the property write-once. But... what if we think of it as applying to the field, aka the backing value? I think of readonly from the view of the public API surface of an object. The property hooks RFC was very explicit in that property hooks are intended to be “transparent to the user” and can be added without breaking the public API. In other words: Whether or not a property is implemented using a hook should be considered an implementation detail and as a user of a class I do not care whether there is a backing value or not. > So readonly doesn't limit calling the get hook, or even the set hook, multiple times. Only writing to the actual value in the object table. That gives the exact same set of guarantees that a getX()/setX() method would give. The methods can be called any number of times, but the stored value can only be written once. As a user of a class the "backing table" is mostly inaccessible to me when interacting with objects. It's only exposed via var_dump() and serialize(), the former of which is a debug functionality and the output of latter not something I must touch. > It would not guarantee $foo->bar === $foo->bar in all cases (though that would likely hold in the 99% case in practice), but then, $foo->getBar() === $foo->getBar() has never been guaranteed either. Properties and methods are something different. For methods there a reasonable expectation that *behavior* is associated with them, for properties there is not. A 99% case is not sufficient for me to rely on when there's explicit communication by the class author that I may rely on properties not suddenly changing. Best regards Tim Düsterhus