Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128145 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 277711A00BC for ; Sun, 20 Jul 2025 17:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753031809; bh=/vvtDeWBaTrJeNdJNmm3AUm4EztidlJJHfV2ezn+4RU=; h=References:In-Reply-To:Reply-To:From:Date:Subject:To:Cc:From; b=eS95GiLMglb+q3KeGAgocaFjzXvMpsDmFo2QhhPdP8YNHmMx0Mr1yWyMl+NHmphTr ZlHTap1oiIprNo77jGgRyfdAYTTtYznTRiB4+JHxYqnTKxJySFJBU+BJpuujSkKXZj 4Uyj8ELOqMsuN7viWld+5mL0ofqOhVl54Q3nNjdCtx9J0XKdGAg/CrtMcP5I19ENMR VQu8quzHDP7F3mYOIkoD74ldAGbrUlABc8aSUURPovFESImoQS/hU/qiBqD6OeQtqN SXgMKCdsWFwWtDPuzCvhXPNDdTimNtDZGsF0LVNoFk6jEp+vMcJ5SMd2j16OW11Wsr 0K/bLbRDVpskQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 11E13180081 for ; Sun, 20 Jul 2025 17:16:49 +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,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-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (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, 20 Jul 2025 17:16:48 +0000 (UTC) Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3de1875bf9dso33167765ab.2 for ; Sun, 20 Jul 2025 10:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753031914; x=1753636714; 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=/vvtDeWBaTrJeNdJNmm3AUm4EztidlJJHfV2ezn+4RU=; b=lr9O5JTGlrn8CydA4F8zrHLLLbMlLmh2gB7v8L3bMHl5gJpe31waULKrZ9D0tCjQ8W +5kxL8oVjFNXC9jVheIesUdCkVIoNaxEdzProDGS6h4yHDl1dhfy4uQZPWf1CcC3bdeN Q5YgbaWP8LSBbvOezYldBHwNm1zEvQNtSOnD56qFEWWWbu44tT567y0jas6vAENrsmGY gFqK4eV9MXtO125izi3n8LgsGbtiMNgmd/7yicge0FTypYDxXhc1UvCw+nEm/BJ7gB1d kU4QODOv6+061PxzsmZ5C0jbBE8LFIDqpM0L/DahQsvUFcq5GJ6GqBcgR0Ix2BcfGzqa LDJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753031914; x=1753636714; 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=/vvtDeWBaTrJeNdJNmm3AUm4EztidlJJHfV2ezn+4RU=; b=o5EzCwaLrEkIiexeWQyPcG7DSglrTawcA9UiBSbjKAsxpAZo7DHcRHtHfTOZEMez9V frkQSBTzckxl0XPHWI+LuWjTfHsDt/50HvJfee37bxQGva3b+BCoIFRS9zrpvK0kD7Mo 0MyXfOLBxeDlldAZWka85ggfUk/SuxwaTdPJ3Rof7qBp088pxPgxAVgeWSBoH1WobuzH KNT1PAyyh9YwhjCKtnw4bTW6MECqTL/ZR4FQaQ6fGYgw6R/ahzUojWt8O58yMu/A300z wD1RwgYoNfOPZQlKmAEpYPr2x3iZ5bNgvur2t02aMrLBh6/BNNle/i0fZZ2g7gEbvSBB 6ypQ== X-Forwarded-Encrypted: i=1; AJvYcCW2a6l/TNtq+JOxtWTXtTEanZtbuWcRAUWONb3gzh82Ofuk689iDwR8lYB/ptZLMwPDNRN8wAfkid0=@lists.php.net X-Gm-Message-State: AOJu0Yx5cd7OdPsyx0M/tCmzlaFJtU/WpNnb434WrBT3ZyCQsXyQfkTS hdZjj+WhKxIMl5LpiOUZgMrJzUDnsI9lSFCXueGF0+FuvjukfHtBgKbE3DH6+HCuRFfK8OuxJMZ 7j2D0zwvJcHh2jIbzzcA86gpIKPX0cKo= X-Gm-Gg: ASbGncvOip4LGU1vszWuaxBfOM0mz58QP/XbB/jXMhWgBi+DKh2G43DCfLR6GbyeDa3 1u4hn0/WZ8mUwU49G0mUCn1GGpNprnI/r6MpLrvtn3u3WaQbR4ok/J/sO+foL6vLP5JjbtzU++Q wo1h2GnbFB/ttL42PxYCml7f5HgRGJLNn/UmJ07fiyqSnwAkcu7EfqAH8YaMeVmP3utDCSc+6Kh /rXW5fTSJH0gL2cSMdGYXJAAHqCtPQTeH3mCsUb3x/6F/m5Z8M= X-Google-Smtp-Source: AGHT+IGZBdrz4k4xwML6LqmZfpY8yg7RJacKwoEzcMpK6KblymjZ6pXAO6uqEKjpJhIjQgJGZKPhCQqfXhosrqHNmkU= X-Received: by 2002:a05:6e02:3420:b0:3e2:9e8b:b64 with SMTP id e9e14a558f8ab-3e29e8b0c92mr92108135ab.0.1753031913097; Sun, 20 Jul 2025 10:18:33 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <378cd8b0-c4a8-4e53-b0bd-e9e4f30a454d@app.fastmail.com> <77128196-8D53-40D6-9BB7-77160AD71ED9@gmail.com> <247034b6-04cf-4f3e-a145-a30171af8c12@app.fastmail.com> In-Reply-To: Reply-To: erictnorris@gmail.com Date: Sun, 20 Jul 2025 13:18:16 -0400 X-Gm-Features: Ac12FXwvBZEjqCvWjvBkH0zADiDl64yqJb0-sk8gp69sG3OtPfvwlzqxwWvXFWM Message-ID: Subject: Re: [PHP-DEV] [RFC] Readonly property hooks To: Rob Landers Cc: Claude Pache , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: eric.t.norris@gmail.com (Eric Norris) Hi Rob, I'm going to respond to a few points from earlier emails here instead of each one. On Sat, Jul 19, 2025 at 6:13=E2=80=AFAM Rob Landers wro= te: > > > > On Sat, Jul 19, 2025, at 12:09, Claude Pache wrote: > > > > Le 19 juil. 2025 =C3=A0 09:46, Rob Landers a =C3=A9cr= it : > > > > On Sat, Jul 19, 2025, at 03:04, Claude Pache wrote: > > > > > Le 19 juil. 2025 =C3=A0 00:41, Rob Landers a =C3=A9cr= it : > > > The original author (Nikita) suggested that there's nothing in the origin= al design that precludes accessors -- and highlights languages where there = are both and they are doing just fine more than 5 years later. > > > Hi Rob, > > It is indeed entirely reasonable to have both readonly properties and hoo= ked properties (aka accessors), and today PHP has indeed both of them (and = even asymmetric visibility on top of that, as a separate feature contrarily= to C#). But it doesn=E2=80=99t mean that it is reasonable for the *same* p= roperty to be *both* readonly and hooked, which is the point that is curren= tly disputed. =E2=80=94 What do the other languages allow? Is it possible t= o define a readonly property with a user-defined getter? (Disclaimer: Even = if one of them allows such a thing, I=E2=80=99ll still think that it is a b= ad idea.) I do not believe I was cherry picking; I share Claude's interpretation here that the RFC says that readonly doesn't prevent the language from adopting accessors (hooks) later, which is what the language did, and notably it did without applying them to readonly properties. Could you perhaps walk me through your thinking when the RFC claims that `assert($prop =3D=3D=3D $prop2)` "always holds"? > > =E2=80=94Claude > > > Hey Claude, > > From what I've seen in other languages, this combination is fairly common= and not inherently poblematic. > > - C# allows get hooks with user-defined logic, even in readonly structs. > - Kotlin uses val with a get() body, which is readonly from the consumer'= s perspective, even though the value is computed. > - TypeScript allows a get-only accessor which acts readonly. > - Swift also allows get-only computed accessors/hooks. (disclaimer, I am not a C# expert) It seems that C# has both fields and properties, and a readonly field seems to align with what a few of us are claiming is how PHP readonly properties should work. C# properties are more open-ended, and don't actually support the readonly keyword - you can make them "read only" in the sense of only having a get accessor (and you can mark that accessor itself as readonly), but this is different from readonly fields, which enforce a contract about the mutability of the field. I think that C# fields, both readonly and not, match PHP's properties without hooks. C# properties - which I believe cannot be *marked* readonly, but they can be *made* read only, i.e. only exposing a get accessor - match PHP's properties with hooks. > > > Hi Rob, > > The main problem is that we don=E2=80=99t agree on the meaning of =E2=80= =9Creadonly property=E2=80=9D. I agree with Claude here. Rob, I'm curious how you interpret the contract of readonly. Do you think that it is a contract about writability to consumers of the class? In an earlier email, you said: > In the example above, there is nothing mutable about it. It is "read only= " from a public contract point-of-view, we just can't mark it as a readonly= class. In this most recent email, you said: > The error you get when trying to modify the "get-only accessor" is `Error= : Cannot assign to 'name' because it is a read-only property` > > Thus, readonly is implied by the get-only accessor, there's no need to sp= ecify it directly. Would you say this is how you are interpreting readonly? That it is a contract to consumers of the class that they can read but cannot write to it? (including a snippet from an earlier email) > I think an init hook is out of the question for 8.5, so I'm not even sure= it's worth discussing. I don't agree that it's not worth discussing alternative solutions to the problems the RFC authors intend to solve. I think it has been expressed elsewhere, but I believe we should take the time to make the best decisions for the language and not rush to add a controversial feature.