Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128024 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 323871A00BC for ; Sun, 13 Jul 2025 21:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752441125; bh=aE7aIgbwzTcUXqNuGyx1OHZPccky8iBJ+zdVPKERSHk=; h=References:In-Reply-To:Reply-To:From:Date:Subject:To:Cc:From; b=l1OnW/uG2KHaM355k6Ik32BUzCWtgWUsT2mnkWl2UczbfZ9tqVBZiY/v0zoZMRhU7 0gDEpJGY5H+r4oy8LPIYORVH72YA0CV4KgzsWbAfBVAkW02Xmg/0QOs5XqR9neQ20K VUBY3Dc5Q/GDRWthse2fGqCpQTHoWMoOfB1aSv0BuBqfl9gj58ffqBWdGtACIwMTZg jR6oNPmKOH/yYzGqaVl816EvVmOdjEJeWtCjnRNVrqxq6rrrW0OI/FTCwtp3HvXv9G 2tIa1NFQB8tldG3s0suop6hO/YIXrNLqsIip7sCp9Qlmwz4E+FD9ov0/X/1EE9Ukmk WvZx+HIH37JMw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A9E981801D4 for ; Sun, 13 Jul 2025 21:12:04 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, FREEMAIL_REPLYTO,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 ; Sun, 13 Jul 2025 21:11:54 +0000 (UTC) Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-875ce3c8e24so146171939f.1 for ; Sun, 13 Jul 2025 14:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752441222; x=1753046022; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=acL+k2WVD3w22pdbXzzDDV2h8fasPcjpazVXDf0gXWY=; b=m0yzP6Drl9d0HAMMHKj0tuO/j/fPu7Sg8DU1/qVdY69J8lvlhNb04k9B7OTsJz9szV gsIJQ1ozjxDe+U4qaaOx775/ug+pbFzwZpd1IHAzqML+Hyc1DxS5MSsogD7vov8Ab0ry r46K/IeH3Fa8knIqlrsjd23Y91VM0fDaZhHc3S1fYudmfbam0BM32VaNGsMWgAYVPJxZ f83NVxNCiJ/2EfRtYGvRV6XvA8x8NJsuzb73Ofl3PhDA1VYKbOtjCJfsv51AmztjamT2 ZVvi3KzT5zNcd2on5WyZ3+tt88JNnX6C7AFSZ6pyuwIygadRJ4OBoeExA09Vrgk6xSr5 xGrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752441222; x=1753046022; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=acL+k2WVD3w22pdbXzzDDV2h8fasPcjpazVXDf0gXWY=; b=xLkDmwkwvw3XwnazSHM3euEp0ToDgyVknMOld0Bnbzf4xHYFU1ll582sim9al3NeDK J8J9UqOzSemBL5UnA/eys0uSRVchhNiUiwaOLqPzDxWdmil2FtY0vUxhgE7XXzP/yUxt hbw9/JXL+aJKEnL2wxe6yqi6Fc9veIrGfJda9t/qHyfIw3ta3x7YuCMFIj6Te7kVLlL8 RXhrKnQAtWuKDqkpePHW2REq7zHw8cTbfy38uxYP4x9fyMwafdrHwoPYNFzAfvfEaKAA KQyWQ9Fb7opUqKNVcgftjkiETwN4mt8/6vfhygG6tQMTOU8J/nZWc6LjkfpTk0IKrVZK FQ3w== X-Forwarded-Encrypted: i=1; AJvYcCVggcY4IiZr4NvbQJdUwVCT/p0V/VQpGjVikvm8CILdKBuL9xjXHmAT2v667FoJ5rshMk6FCnRfP1g=@lists.php.net X-Gm-Message-State: AOJu0YyiEZTHXYWBgGskh2j4b2hCY4BR4qJyiTlJnHQ5WbJ8O6FEkbRA Bw2qdZi9VLZO8ZOGZMwPmsfFv5Uq25M6lxDnHBdVAxiioy2cMbE7GwL2254Eqc+w2AoX9sjV0N6 z30WA47f/MsFiGk0zqmyHyYOeas+/E54= X-Gm-Gg: ASbGncvul7kSuZn70cFu311oTGl+u2amdVDi5xpbXUfC0pqyVd8Rg+2Bh8nkvRhUxOS T/PJwTbKHIEYIRTcqk0WpLuHfB+O3rQTA54LmYbSQW/ZkKlXegK29737vNBpJNyY6WEJeY3NwqH RhDPQ51uyHPO/4JTRSrCMHnH1exqF1fxYoy6IwSkUV5+e18xnusQZcg4+XcBgjBst0dlg5s1IDG vNmUd1tjyLSGePgtfmIxs+qKQPL7H3FIZ14w2TY1g== X-Google-Smtp-Source: AGHT+IHmMmDo+OW9Mjc49G4PvVeAK/iHiTr9sHkZdUNv9s7ujRwxOMyQ2zgrmYvpg5PF+KAuCqmh4aT8E+j2uLUmkB4= X-Received: by 2002:a05:6602:3a13:b0:86c:f2ea:d8d3 with SMTP id ca18e2360f4ac-87977fce862mr1057510539f.10.1752441222198; Sun, 13 Jul 2025 14:13:42 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <1e8634d7-ac1a-4025-b4e2-1948aabf5251@app.fastmail.com> <9D5043B2-1589-4FD5-B289-6E98FB1177BE@nicksdot.dev> <16BD443D-A179-465D-84A0-6E3780F62D8E@gmail.com> <203C1BD7-E688-4E26-8EA6-EA5331525470@nicksdot.dev> <71E5E8FE-605D-4B32-8CCD-F7ECBD454E24@nicksdot.dev> <97C001B0-05DC-4797-A72A-F82E1A0AC30F@nicksdot.dev> In-Reply-To: <97C001B0-05DC-4797-A72A-F82E1A0AC30F@nicksdot.dev> Reply-To: erictnorris@gmail.com Date: Sun, 13 Jul 2025 17:13:26 -0400 X-Gm-Features: Ac12FXxpHquIDvaQ3PhFwkKwjAeMXgdlV08EHz5r_JW2CVgl22M8QHMaB5_cTT4 Message-ID: Subject: Re: [PHP-DEV] [RFC] Readonly property hooks To: Nick Cc: Marc Bennewitz , internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: eric.t.norris@gmail.com (Eric Norris) > Well, I don=E2=80=99t know. Everyone seems to think of init hooks (and th= eir playing together with other hooks) differently. > Some say this, some say that. That=E2=80=99s the exact issue. Want an exa= mple? > > Eric just agreed with your code example which has a get hook AND init hoo= k. > > ``` > class Test { > public int $seek { > init =3D> random_int(0, 100); // called once on read if not ini= tialized > get =3D> $this->seek + 100; > set =3D> $this->seek =3D $value + 100; > } > } > ``` > > var_dump((new Test())->seek); // number between 100-200 OR 200-300 depend= ing of the set hook be called once with the result of init as well. > > Or did I misunderstand it? > > > I share the same understanding as you, Marc. > > > But one mail before he answered to Larry: > > I think, at least for readonly, you couldn't have an init hook and a > get hook, since the main objection here is to having get hooks on > readonly properties at all. On normal properties, I think that'd be > okay? > > > So what is it? Get hook cool, or not? And how does an init hook work exac= tly? > How play all combinations together? And how with readonly? > Why didn=E2=80=99t your example use readonly if we talk about readonly ho= oks? I believe you are attempting to point out a contradiction, but as far as I can tell my two statements are consistent - his example did not include readonly, and it makes sense to me as-is. My prior statement to Larry is "I think, at least for readonly, you couldn't have an init hook and a get hook". Again, his example is not readonly, so it's consistent. > Eric, > why it wouldn=E2=80=99t be solved by an init hook? Well, because as you s= aid, readonly get hooks would not be allowed in combination with init. > Others apparently have different opinions. So will they, will they not? I don't think others have different opinions, or at least I haven't heard someone say that readonly get hooks should be allowed with init. > > I, however, want get/set on readonly properties. And that is what I propo= sed here. > > An init hook is not part of this proposal and I am not planning to take t= his on. > This RFC, however, would not block anyone from creating their own RFC for= init hooks. > > B) Less Code > > Marc was talking about init, cache modifier and attributes in the same ti= me. > Claude initially wanted a cache modifier on each hook. > > I argue that =E2=80=9Creadonly implicates cached=E2=80=9D is very reasona= ble here. > > Many, many opinions. Many, many options. All have their pros, and cons. A= ll can be attacked, and defended. :) > > All I want is the below (less code; and no dealing with unrelated things = just because I want to add hooks to a readonly class). > > ```php > > // I have a nice readonly class > final readonly class Entry > > { > public function __construct( > public string $word, > public string $slug, > ) {} > } > > // I simply want to add a hooked-property to that readonly class > final readonly class Entry > > { > public function __construct( > public string $word, > public string $slug, > public array $terms { > set(array $value) =3D> array_map(static function (Term|array = $term): Term { > return $term instanceof Term ? $term : new Term(...$term)= ; > }, $value); > get =3D> $this->terms; // something, something > }, > ) {} > } > Your example might not need a "get" hook at all, if I understand correctly? The default behavior would make sense here (and, it seems for at least some part of the mailing list, is the *only* thing that makes sense). You would need a "set" hook, but I don't think anyone is objecting to that. If you'd like to propose "set" hooks in isolation, it seems like it would pass. > And for that, I believe, I provided a solution that is easy to reason abo= ut (all details in previous mails), and allows everyone to achieve what the= y want. I appreciate that you are focused on solving a real-world problem, and that you have implemented a solution that addresses the problem. I can understand that it seems like it's in reach, and that this conversation might feel like we're wasting time. That said, I think a number of people have reservations with the semantics of get hooks with readonly, and it's important that we take the time to ensure this feature is one that makes sense to all developers, and continues to push the language in the direction of being more consistent and hard to misuse. In an earlier email, Larry said, "`readonly` has always been misnamed; it should really be `writeonce`, because that's all it is. (Once again, this is likely the most poorly designed feature we've added in many years.)". I hope that I'm not misconstruing what he meant, but this makes it seem especially prudent to avoid making additional mistakes with regard to readonly.