Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128103 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 B6E761A00BD for ; Fri, 18 Jul 2025 12:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752840854; bh=zaP+nlm17qvNy371/pygWZTPcbemTrHilVLeTtc1yv8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=hFKhdbcZUoNHYV8CWsS594rKKSbd253s7I4fYxZFzXI/Ue0FT7EtgYRDFQCDlq97c oqWRLnL4KvXneGucrNRQsCRGvdk7yIDrldday6k7XZvpNCUNRYvoiNac3UX4YBBort Br0dPVNyPUFT9DXn1OJI8cy6md1XnpL+Qh/XxBqqebQYdcvbNqb5OmZqaFr2taIpm+ 2eKqJdNp0LeQjV4nUp33U9EmWMy1H0apklExV6eg30bpiwO15w1UnHb76Qp2AHgq1I a0A9tYpa5ypeKmeprqG9BGa8migeExZVzpilbAIJKdzrIdV30fxnwYr/4qMuZdjO0P 22a5bISWeOp0A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E45971801DA for ; Fri, 18 Jul 2025 12:14:12 +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.7 required=5.0 tests=BAYES_05,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 12:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1752840945; bh=gtIPXN3y5RGz5F0Vh2RU85tAoed4xpLSYaYWYeQMkcM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=hgDI3KbWeuTdg8qvx+YicHNsLjlf7+RJQ8Fshmx57kYaS8t31oyjsJHhpYILRZMoc rmJ+CxBeQUO3HRLN3CDkVF9W001SyfdbntC2sl/Vo3HvNmalSuca+pkmmEBFCCLpzD plz9kOUbzFBuS/B05TiJkfekDDYzskjakx5G1tg2sATSGCF4u3XfFAoX2QAUnyb1pN c3dydduR93UE0dVe8x1xsJqOBUrNl81pGNkOLDHEMIJtNBNUK2J3hgD80j98a+gbYG h40UQ2AzFOKxxzJ8rUGPlomX6YF6F8Bl+xLAMDC5Jx8Rokrqy3ypnPtyOQHDKPiPXi tMqkEQCNHjXhg== Message-ID: <1c9628a6-217d-49e1-91a3-555402ecd3b6@bastelstu.be> Date: Fri, 18 Jul 2025 14:15:44 +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: Claude Pache , Nick Cc: Nicolas Grekas , Larry Garfield , php internals References: <1e8634d7-ac1a-4025-b4e2-1948aabf5251@app.fastmail.com> <46857A6D-5EAF-44AF-A2DE-9B40AF8DE8C8@gmail.com> Content-Language: en-US In-Reply-To: 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/9/25 19:58, Claude Pache wrote: >> I hear you, but I still struggle to fully grasp the issue. It’s genuinely hard for me to come up with a real-world example that actually makes sense. >> Everything I’ve 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’s 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. — Indeed, I don’t trust users and want to protect them against themselves. > Full agreement on Claude's entire email, but particularly this part. Users have expectations from seeing the `readonly` keyword and adding the `readonly` keyword is an intentional choice by the class author. The language should not allow making it easy to violate these expectations (by accident). This is no different from the language making sure for you that you may only return values of an appropriate type from a function having a return type. The `readonly` keyword is part of your public API just like the types are. Best regards Tim Düsterhus