Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127966 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 DA2081A00BC for ; Wed, 9 Jul 2025 10:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752058272; bh=zr8ZzeV9nFW1AOo8RPTQAcg1TGU0XWdbE5CTmERcXic=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=mR5jBotTFkTyPf0UV93D+Eft8w7sHL0dCNB6l9POZRXoeW0GRpmqfG9BgwmtoJAMa g/avWZWfG9FqV32X+eTxCyhVq9sSLOxXFxBcxKQ6wOUUMScTUYeUfqEJNjWLbLzcoo h7M2Aa266XTqT14VEKTC2hAl7c+4HawZNUyVGcV2Bgui9j0xdIDHEhteQgBr8mXJWu qjFkyEyyEFZ8PgXGwwsLSmBO86C+5QxElXUF0lI8YUtg6uSDCtNL48YJk2kObkQotp rF7mNaXj6/pJ6Av0QQ176+OInJ+ScqR4vxi+DRUkrVvPq/PtgRKy+TVtxaGB0+d309 8sBM8rMkX0jvw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 96E5A1801D9 for ; Wed, 9 Jul 2025 10:51:11 +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-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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, 9 Jul 2025 10:51:11 +0000 (UTC) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4537fdec33bso34103895e9.1 for ; Wed, 09 Jul 2025 03:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752058380; x=1752663180; 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=6QiSuUrlB3oobNB72SMFMWebk3UoUrc5d8XxlDm+pUc=; b=QW7NklR5UrX3BghBkdK6ppqkmMdf+VtjbrINWILXOKfT0SIoovqR5dpYlNiNOGmkUj MChOyxuf+o1F2TqRqFBQhdgOBES6XsfeYlVLHM9fgNPOuS8ZOWMFsF6DuRpqPYfgjcFM LzNUECy7a1mfEncdTb4mVyzAQK3Bqg7CuEshmJmPwfISbO6dsqLWXFllJkmgk7t1Wr4S JJ3VgtBAq3CR1UHjkFaAt2rvol4jpASTAEnO91UJnH83q9uoxIbI+/Qf7d5Sy6zl42XO I1FQL2i/uD0tlt++MeGO7aWgtBvntSQZueqhbPgKHiRhtjIwzlSwk6OWj5cCM3sVNciJ k2oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752058380; x=1752663180; 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=6QiSuUrlB3oobNB72SMFMWebk3UoUrc5d8XxlDm+pUc=; b=bt7xqo67lUGZ+r/dyiHtd6nNL8w7QEN/bTVFIPGUGCpnCEHBjOxKHTyRX6lAS7BkAe 18IjaeMk/sUFWKBbhQw9t4gmPI+lFJ9AJd6rrw+krfXtGaKAFar1Fap3ayqyGVao9o8T DYFZIegZn0C14QXAWxS9usfMxPV+kUPEQrg8fPKfiNGT5M//sda0AKr0PNkekZ2rsXN3 eSmaCswowN3c8s53ZMngaGNIpkU+976ydq4WD3ulRnZMVRelZU34qZfxDDhKz1lIhW/z 6OakcoMm2dMWy30tz4Cn7qw8gCAsLixEreQwUUAXySt+UAWfXxAolO0Zyc5Aoxs30prp JjSg== X-Forwarded-Encrypted: i=1; AJvYcCUKvl4whl1DWAgnjWhhEoFhex5hmMivoW8g9JmPae32ruex+lC4JHkfL1oyCnwAd8BF1xAP7oGcQ5k=@lists.php.net X-Gm-Message-State: AOJu0Yx9XsuGWNdpYZDvlsp+UZmPO+hPhATBhlzWw2UX1zFZ8nf0ttyk D3Zoz1zIIiFl8OVcAQHryG6RD16HqJ8Ww4LABWsGvN88pAaTYCL/EHxf+KONJQ== X-Gm-Gg: ASbGnctLDiJmQ9AnGXj/jDVPveTHZ+UluUkCNEi5Zh++5RpB4epvNYEUPRYaEz2+uIW TmI9SLEr7t7ibVhfo5yzJRkVHagWp8i+rxVyC0RALRZSCLgtV3u7+eNv1+/GM0LNCUSzImoD3/F i1yLtEnTCgJUnEUnBWW7jeo1JOvFLEF0HNQPHlWvWM/7H3hXh5seAWoCylHRR/cLdBKigETxdIJ e3rphzuPAfCZUA8q+XX95haOELt/0mKuNveYdsL/usjEWyxwayo2JfdqByNzZW0Tmakk1ODnEL6 yfCj6k9OE9QrC0DohQdeFP9RGua0qNh42rsQ5GN7Okwz3U/Nj04nrx7DVqS1a68Xk4VhZXCThiV aPc94 X-Google-Smtp-Source: AGHT+IGb3drMevsdVognei1DJDlFzmJzT+UCb+aUI90hc0/64Was7Ib/v/K95OK5WGXgydod5A6+LQ== X-Received: by 2002:a05:600c:64c6:b0:43c:eeee:b713 with SMTP id 5b1f17b1804b1-454d538f8f3mr16874115e9.20.1752058379797; Wed, 09 Jul 2025 03:52:59 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454d50702bdsm19644335e9.25.2025.07.09.03.52.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jul 2025 03:52:59 -0700 (PDT) Message-ID: <46857A6D-5EAF-44AF-A2DE-9B40AF8DE8C8@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_EAF221E1-85D8-4A04-8B4D-AD4D2FC11E04" 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: Wed, 9 Jul 2025 12:52:48 +0200 In-Reply-To: Cc: Larry Garfield , php internals To: Nicolas Grekas References: <1e8634d7-ac1a-4025-b4e2-1948aabf5251@app.fastmail.com> X-Mailer: Apple Mail (2.3826.600.51.1.1) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_EAF221E1-85D8-4A04-8B4D-AD4D2FC11E04 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 8 juil. 2025 =C3=A0 17:32, Nicolas Grekas = a =C3=A9crit : >=20 > I read Claude's concern, and I agree with Larry's response: the engine = already allows readonly to be bypassed using __get. The added hook = doesn't make anything more lenient. >=20 It is true that readonly could be bypassed by __get(); but this is a = legacy behaviour, and you have to take an explicit step to make it = possible. For those unaware of the awful hack, here is a minimal test = case: https://3v4l.org/N78An where the `unset(...)` is mandatory to make it =E2=80=9Cwork=E2=80=9D. Are we obligated to sanction shortcomings of legacy concepts in newly = introduced concepts that are supposed to replace them? Or can we do = something better? I=E2=80=99ve outlined in a previous email what I think = is a better design for such situation (namely an `init` hook). Also, the fact that __get() is not yet deprecated means that we can = still use the aforementioned hack until/unless we=E2=80=99ve implemented = a proper solution. In the worst case, you can still use a non-readonly = hooked property and document the intended invariants in phpdoc. > If a class is final and uses readonly with either hooks or __get, then = that's the original author's choice. There's no need for extra = engine-assisted strictness in this case. You cannot write such code in a = non-readonly way by mistake, so it has to be by intent. >=20 Enforcing as strictly as possible its intended invariants is a good = design for a robust language. Yes, it implies that users cannot (or can = hardly) escape annoying constraints. For example, you can=E2=80=99t = extend a final class, even if you think that you have good reason for = it, like constructing a mock object. =E2=80=94Claude= --Apple-Mail=_EAF221E1-85D8-4A04-8B4D-AD4D2FC11E04 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 8 juil. 2025 =C3=A0 17:32, Nicolas Grekas = <nicolas.grekas+php@gmail.com> a =C3=A9crit :

I read Claude's concern, and I agree with = Larry's response: the engine already allows readonly to be bypassed = using __get. The added hook doesn't make anything more lenient.


It = is true that readonly could be bypassed by __get(); but this is a legacy = behaviour, and you have to take an explicit step to make it possible. = For those unaware of the awful hack, here is a minimal test = case:


<= /div>
where the `unset(...)` is mandatory to make it = =E2=80=9Cwork=E2=80=9D.

Are we obligated to = sanction shortcomings of legacy concepts in newly introduced concepts = that are supposed to replace them? Or can we do something better? I=E2=80=99= ve outlined in a previous email what I think is a better design for such = situation (namely an `init` hook).

Also, the = fact that __get() is not yet deprecated means that we can still use the = aforementioned hack until/unless we=E2=80=99ve implemented a proper = solution. In the worst case, you can still use a non-readonly hooked = property and document the intended invariants in = phpdoc.


If a class is final and uses readonly with = either hooks or __get, then that's the original author's choice. There's = no need for extra engine-assisted strictness in this case. You cannot = write such code in a non-readonly way by mistake, so it has to be by = intent.


Enforcing = as strictly as possible its intended invariants is a good design for a = robust language. Yes, it implies that users cannot (or can hardly) = escape annoying constraints. For example, you can=E2=80=99t extend a = final class, even if you think that you have good reason for it, like = constructing a mock = object.

=E2=80=94Claude
= --Apple-Mail=_EAF221E1-85D8-4A04-8B4D-AD4D2FC11E04--