Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128133 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 C8B421A00BC for ; Sat, 19 Jul 2025 10:09:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752919657; bh=r1Lm51xoahc9IAbzvHM7ElFG3QLKjK4MVvZctn5uz+I=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=W2I+kFEmvqB5OYw92taOuy+PpxlpKvqF3iVg6Gti0hiYDV9LIOZtR+1T0DnUovl+c 0Kne+R5/3B2HsQU4cAlxGt9sHvWEmQeVHjX4UikkPo0hwx2zVbd+Ai/ktBxQb18a3E ihWPX098Ir3qXPqTLWd6eCyQvdO0CEyyYCE+xXqOSlIFcggvMBSbHXkeoUgUBj1H41 d/b82WVxM98FN4/vyzfnvpWOWt9mbJP7SSgizO0N7lJ96yMh5t8z9ANzGHTwtSIq4+ JmP4Z10DMyNvrdMe8gSgSPdwjNdLIarJaS+leQyZz0nZU3tFhqLj3x+2xRqKz2lffg YrbEOje8IdNCQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 403FE180054 for ; Sat, 19 Jul 2025 10:07:36 +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=-1.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,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-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 ; Sat, 19 Jul 2025 10:07:36 +0000 (UTC) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-45555e3317aso17374925e9.3 for ; Sat, 19 Jul 2025 03:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752919761; x=1753524561; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=kuE2zVmlL76ujcKoNWIknpGW9a9whA0191Ei28qXr3I=; b=fQ2Hxh40wDrJL8cZ3PrhAFdOmbcDYIANVVeco0PImd2x7xoDIp4nLyDGU17ghg377N mI3akG8dRZfgV987bMl6sjqs8KbF94eCdd2O5+Nbh9Jr9sMw/91Y+br3mniOg6D/FhCm WME2j69lssHqCM+TS4lZT81BfjVAKm+/o6BQnnEW6RQxZNiSg6fSsAVLt/wT0tAgtSZE rOutwU5H9tvB4jldt9roLDkOZ6vvRIi3kiwz5eJJNSwyw91jVJSfAzM5zrI5XC/3bzaL ng6fz6+2ZdiW/Ox/YmRDqpzr+iA2nf1k8quEteeDulfLtbOYV1VnqfdO80soVE4XXFWx ehtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752919761; x=1753524561; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kuE2zVmlL76ujcKoNWIknpGW9a9whA0191Ei28qXr3I=; b=PpOGYDqA0tg50BxTn4hEUIW1VZyrklH5it+aBWbd7XkXhx0edNSz45tr9S1Vmpw3JH iNPkrkI2kREoM8Riq11BGDdL1Wx9YMqXcRMbME39AjoOW/PAzalW8BBXoPYk4Wx/7Zmm 40pQodTl6OXGLfx58mRm70Cb3Uah0h4awBhfoSUbjc9kXEZn1uhyiGRTwRPc3W1zQuSu uD8H2uVXVGaZGKug8IKbqeA+ljMjJgJyYiLK7ltNyBEqJvQuH8xcpyzlQ59J/klbL5XS tQljMeK1BIcMLu5NFgERxZyTpPHvpR5QeHlFB+Z712A2jMPJ8+/rL18dnwYE0lPooKke 6YiQ== X-Forwarded-Encrypted: i=1; AJvYcCV87qXiZC+KLoiK0YWMLnZBY4R2A6g56EvIcqQJuuEx+Fwe755XaerWKiGq7BD6Jw3eautfzl3VpI0=@lists.php.net X-Gm-Message-State: AOJu0YwTvz/jPV9rO6PHAfpcRxsrlUvOU4s6fnB3baPQ1GQWgHiNkZcb dsr3WQqbbVJxhBYbmJ4PomQuQ1Qus/zX24P048k7ZJXbzuTgjyVb/7Yy X-Gm-Gg: ASbGncva7QlKGfiBA5MDa9O0rlLn5/RcKI/X69DyTsKTetpueb2rmG5P50n1ukuqkcv o/0Y0ekLtssJsGiEUWe3+pSt1fux21PLhhirynf3ufql/gF1uWCxvZxNIkPwTSHkBVb8Lw4owH2 OKtk2c3azkb/ESSpqrun5imQElAJqaY5YaIMQtB+py9ExNtxMoM8z4Vzpt3cOfnjNfHLk8Y0Y4w pUDDM36P1awvK04OT2Y1Luwi/qnVezLRjZg7XYtX6eDsXq06Z/ceIM5YxygaoI2WUWl4i8oUhty AEksjpmP/O53iBAxomQ/pCQo08VdF0o35/t/HKsrUSTj/ymGFFoIrgYMRhX9hiYRvUZa9oagXev 0m0Wfm47vRHtTZHbjEDRqF2KiZRb9I/fMnsDsIWQz X-Google-Smtp-Source: AGHT+IFUQupfgCoJcLumjz6CYRY0KkByDpmjKZtRzk+orqc11RUbjCGlDPvVFn/kEU3eRWFxrp3QKQ== X-Received: by 2002:a05:600c:3488:b0:456:f00:4b5d with SMTP id 5b1f17b1804b1-4563a1f42c0mr59324435e9.22.1752919760776; Sat, 19 Jul 2025 03:09:20 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4563b74f78bsm42691895e9.27.2025.07.19.03.09.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Jul 2025 03:09:20 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_2F480B57-EF57-4C3A-8B35-084F84D42FE5" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PHP-DEV] [RFC] Readonly property hooks Date: Sat, 19 Jul 2025 12:09:09 +0200 In-Reply-To: <247034b6-04cf-4f3e-a145-a30171af8c12@app.fastmail.com> Cc: erictnorris@gmail.com, Nicolas Grekas , Larry Garfield , =?utf-8?Q?Tim_D=C3=BCsterhus?= , php internals To: Rob Landers References: <378cd8b0-c4a8-4e53-b0bd-e9e4f30a454d@app.fastmail.com> <77128196-8D53-40D6-9BB7-77160AD71ED9@gmail.com> <247034b6-04cf-4f3e-a145-a30171af8c12@app.fastmail.com> X-Mailer: Apple Mail (2.3826.600.51.1.1) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_2F480B57-EF57-4C3A-8B35-084F84D42FE5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 19 juil. 2025 =C3=A0 09:46, Rob Landers a = =C3=A9crit : >=20 >=20 >=20 > On Sat, Jul 19, 2025, at 03:04, Claude Pache wrote: >>=20 >>=20 >>=20 >>> Le 19 juil. 2025 =C3=A0 00:41, Rob Landers a = =C3=A9crit : >>>=20 >>> The original author (Nikita) suggested that there's nothing in the = original design that precludes accessors -- and highlights languages = where there are both and they are doing just fine more than 5 years = later. >>>=20 >>=20 >> Hi Rob, >>=20 >> It is indeed entirely reasonable to have both readonly properties and = hooked 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* property to be *both* readonly and hooked, which is the point = that is currently disputed. =E2=80=94 What do the other languages allow? = Is it possible to 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 bad idea.) >>=20 >> =E2=80=94Claude=20 >=20 > Hey Claude, >=20 > =46rom what I've seen in other languages, this combination is fairly = common and not inherently poblematic. >=20 > - 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. Hi Rob,=20 The main problem is that we don=E2=80=99t agree on the meaning of = =E2=80=9Creadonly property=E2=80=9D. I=E2=80=99ve check TypeScript: * It has getters and setters, which correspond to PHP get/set hooks = without backing store. * Separately, it also has a `readonly` modifier that can be applied to = properties; the semantics is that such a property may be initialised = either at declaration or inside the constructor, but cannot be modified = afterwards. That corresponds approximatively to PHP readonly properties. * But a =E2=80=9Cget-only accessor=E2=80=9D is not the same thing as a = =E2=80=9Creadonly property=E2=80=9D in the specific sense of =E2=80=9Da = property decorated with the `readonly` modifier=E2=80=9D. Also, you = cannot add the readonly modifier to a get accessor. =E2=80=94Claude --Apple-Mail=_2F480B57-EF57-4C3A-8B35-084F84D42FE5 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 19 juil. 2025 =C3=A0 09:46, Rob Landers = <rob@bottled.codes> a =C3=A9crit :



On Sat, Jul 19, 2025, at 03:04, Claude Pache = wrote:



Le 19 juil. = 2025 =C3=A0 00:41, Rob Landers <rob@bottled.codes> a = =C3=A9crit :

The original author (Nikita) suggested that = there's nothing in the original 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 hooked 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* property to be *both* readonly = and hooked, which is the point that is currently disputed. =E2=80=94 = What do the other languages allow? Is it possible to 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 bad = idea.)

=E2=80=94Claude 

Hey Claude,

=46rom 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.

Hi = Rob, 

The main problem is that we don=E2=80=99= t agree on the meaning of =E2=80=9Creadonly = property=E2=80=9D.

I=E2=80=99ve check = TypeScript:

* It has getters and setters, which = correspond to PHP get/set hooks without backing = store.

* Separately, it also has a `readonly` = modifier that can be applied to properties; the semantics is that such a = property may be initialised either at declaration or inside the = constructor, but cannot be modified afterwards. That corresponds = approximatively to PHP readonly properties.

* = But a =E2=80=9Cget-only accessor=E2=80=9D is not the same thing as a = =E2=80=9Creadonly property=E2=80=9D in the specific sense of =E2=80=9Da = property decorated with the `readonly` modifier=E2=80=9D. Also, you = cannot add the readonly modifier to a get = accessor.

=E2=80=94Claude

= --Apple-Mail=_2F480B57-EF57-4C3A-8B35-084F84D42FE5--