Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127581 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 D7C6E1ADC9B for ; Wed, 4 Jun 2025 13:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749042451; bh=T2ttweEu86YdfPcJamuwi6mRIiX9BExvLXUb4S5u2QI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Te1oC+iWoN9/d9/dM6I6ZH3JaLzo6wW0bUlk2izj2t8QxXQ2SWWq92YrIMNyBUh6R XrygTHvfKvXkfpf5syHyBlzp+lfyZVS0u4S3xMtHv3I/jQSLgon7VSLgj0kfDAddrX dHAS38TJWKX8bxxMjSmFKqb2RFvHFvHauNBFQpfZ0Yev+r1LvTsTGZrImSeC9e4yrD frtsuUHs3KtjBL/KIAPJ1eIWrBRHYAIvN9BZW7dEqWAIm1cn94QuQQiuDNHmMAJuU9 0EQGn7RhVaoUpdZ2DzkwnYRx9+PdHqOd7H+zal7pLV+NWgUeEF4dH5v8TqIFvcFwzR YaruQDoJb5Jlg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CEBE118038B for ; Wed, 4 Jun 2025 13:07:29 +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 ; Wed, 4 Jun 2025 13:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1749042569; bh=YxDrHBU3HxMzIpmJBpgh0OCn6YOt06kr6HPSeaqMPTA=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=Cp/CSGUCYfrYUZe79WGqB4z4LyeF5QqZCpCf2twxbdcAsS2FfrB6cGzj9rKJ9jmo9 k6BVEb1DuU+GvKwVwdlxdwfBAmxjcmuCm/XToDECz6NEYPNlxdx9wrDQObO+E5xctv 1pH48Q4efoosCJJTNeeCj0As1Pf1OuSH2bniRGCF53O9Nas/hI66TlmbwYUkiZkQ9U 04G798sdBP87CmRXvg+JkK+ThKVbCZjH0agBWXlTDM/MWfIDenK1KogKJcoiBKKFVd sBD7F8XFVwhT8CGxSBPcYfFJPbJyV6HebX8a4/dgv4hvZV0XJv8Ph3o2TVYxbPzCSu DjXiUm7GkN2jQ== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 04 Jun 2025 15:09:29 +0200 To: Nick Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Allow hooks in `readonly` promoted properties In-Reply-To: <26AA81AF-1610-494D-A811-10F7B282CBD4@nicksdot.dev> References: <28F14D0F-8483-418D-85D1-660564A4EAE2@nicksdot.dev> <26AA81AF-1610-494D-A811-10F7B282CBD4@nicksdot.dev> Message-ID: <1c0df916e4cfbc746b5dddf935d165a9@bastelstu.be> 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-04 14:19, schrieb Nick: > Fair. If someone really wants to add random_int(): "well, that > assumption doesn't hold anymore, deal” from my side. 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. 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. >> 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 “you can just do things”. 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’d appreciate feedback from > people more experienced than I am. Thanks! 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 Best regards Tim Düsterhus