Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124196 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 qa.php.net (Postfix) with ESMTPS id 90C161A009C for ; Wed, 3 Jul 2024 13:30:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720013483; bh=b6KN4YDsi9OemR+yxvNGVUEi3e6J5/OZdHBN9pgfKUk=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=J7xWyNCg7jYHP+Ava8m30K7JoCHjV8aT/fQHfJk/tlxRS/A6uEWnyZmkJmF5LxAv+ uFGZkXwdNWgKuZ4e+sax7T6W/BkW9JK1xlzBxqwEVM6vDXmGlYMW9jx/6sDV4bboXq hykeHcKOrndcPYCfQmSol9AC5t99fwqIP6Ydndh7UqHOKICBDx0l7X1Z1nVqbQiIsG l383ZMiW+0O9WwEk/teX65mrQM9zDgdX8+3GSfKuxh3hmCmHG+3SQd5eC/gWDDbMbE 94wu2cAa5D3ypLPjSUSvchMtPWO/MhFKKW4z1RH4wGV2OURvJUSs6PBG4qhenJGPzV xyO/kS1PC5lMQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3EE0A180D85 for ; Wed, 3 Jul 2024 13:31:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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, 3 Jul 2024 13:31:21 +0000 (UTC) Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-57cbc66a0a6so1184234a12.1 for ; Wed, 03 Jul 2024 06:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720013399; x=1720618199; 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=WxZMI37GoMx48PrwKleXtufMm+wmEveXU+WXhk8/71M=; b=LwaH18CJR7HrqURQLSc4sNY7Zhexjmx4p/xAmzgxT2d9Y/gsH4UkTbcn/Ou0KT2vev Su6j2+xKRaTa5JYHPo5mkAHPZWCygpvejKajtUKqXGwXd4P9Nnk0XR+C0ikgFvYq3qGZ oJwjMssbXPc/b+CqeC5zhDD6ysDI6jgTy/P+cjN8R2tzu/At7T2um9jSHW6CyB6IOevl 5VqeGPi8YCLfAH/32MmRc3SY4t+ywYWEDPlX+ioyjXkWIL8tdoqqAz/e9yRNoaL9y3E4 0SgLDeNV8PVw+DL8ko5OEsKoE1oFFv7zNHoPbVM42ojs9yLbI2wqwaUauIvxdC8Pw5KJ PrnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720013399; x=1720618199; 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=WxZMI37GoMx48PrwKleXtufMm+wmEveXU+WXhk8/71M=; b=fyzYTrVzmS0yNcF/emJSXZutzjYPRAGfB0Hv5Fl9k7b33/DTYjeKoUixrDJfO7O84y Xffx0H/BgLFx87y/dbswICujm6DAu+kEsXUyyTFDOVIDUJ+JqI62yU8RUCy9mrUea+F+ e94bQNZ0S5SA7PfRH7wDgXWmSAzseGM3+fhJEgccenQAtSZxBNY7XQ+RSMouyWk773Ro q3/RzrGQ9eIUy3zNKlcNOh7yPVfa4puRE9aPA7yxB05nQWu6vD1/xpOPryGA/D8v1qEp axLQPpvh7ujxn/FfuBmxXE1A/niamgOXBkA9rHM24Cxx+AoyrsC5z8oldyzxaBPtC/ev vbbg== X-Forwarded-Encrypted: i=1; AJvYcCXeqSR8MFaKDvrqgyP6VNIlN0QQ3ayFf1BeaSP9J9Uy1+Pp70EmJx5GneTGxBaGUi5L09X+wczxmtZNB/tbz0aJ/Pxso8zhbw== X-Gm-Message-State: AOJu0YxpCBgfaQqv7jla2aw61jGNEYTNSiTj9WSRZ9YMvHCVjnGYevUZ kIVqqiIfNQ8AcAkLhuAfG0AdtYepRdaqhr+DVAJ7PZLD+FnwCsaLlqshSg== X-Google-Smtp-Source: AGHT+IGxLBOTjfrgyMMaOwtyEPZAD+UsvPaCbJXLwI3D4uKq2W9cL0fGI3N+uYsjeqZ08iRp//Hvsg== X-Received: by 2002:a05:6402:50c6:b0:57d:4409:4f48 with SMTP id 4fb4d7f45d1cf-58ce65c7aedmr1642762a12.15.1720013394493; Wed, 03 Jul 2024 06:29:54 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58ceee04b51sm769075a12.71.2024.07.03.06.29.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 06:29:53 -0700 (PDT) Message-ID: <063761C9-3DAE-4F3C-8279-F2B1636EF953@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_C7A60B94-72D6-40FF-AD4C-FC77FF7A42C8" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: [PHP-DEV] [RFC] Property Hook improvements Date: Wed, 3 Jul 2024 15:29:42 +0200 In-Reply-To: <557008ce-30c4-4002-b731-1faabe487e64@app.fastmail.com> Cc: Larry Garfield , php internals To: Rob Landers References: <8A3C2FDA-60DF-45A1-BA9D-11B6FB6F755C@gmail.com> <557008ce-30c4-4002-b731-1faabe487e64@app.fastmail.com> X-Mailer: Apple Mail (2.3774.600.62) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_C7A60B94-72D6-40FF-AD4C-FC77FF7A42C8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 3 juil. 2024 =C3=A0 14:42, Rob Landers a =C3=A9cr= it : >=20 > On Wed, Jul 3, 2024, at 14:28, Claude Pache wrote: >>=20 >>=20 >>> Le 3 juil. 2024 =C3=A0 11:54, Claude Pache = a =C3=A9crit : >>>=20 >>>=20 >>> 2. As for readonly, I think that the invariant it is supposed to = provide should be enforced as strictly as possible. It means that = `readonly` is only acceptable if there is no `get` hook. >>=20 >> Hi, >>=20 >> One more thing, why I think that we should be strict here. It is not = just for preventing the user to write *dumb* code, it is also for = preventing them to write *creative* code, e.g. >>=20 >> ```php >> class doc { >> public readonly int page { >> get =3D> $this->page + $this->offset; >> } >> private int $offset =3D 0; >> public function __construct(int $page) { >> $this->page =3D $page; >> } >> public function foo() { >> // $this->offset may be adjusted here >> } >> } >> ``` >>=20 >> =E2=80=94Claude >=20 > I don't see anything wrong with that code. $page doesn't say = "immutable" it says "readonly", as in "cannot write to". >=20 > =E2=80=94 Rob The fact you don=E2=80=99t see anything wrong is *precisely* the issue. = According to the original RFC [1], the intention of readonly properties = was immutability, not just non-writability. For the weaker case of = non-writability, it was explicitly mentioned the possibility of (future) = asymmetric property visibility. That said, I agree that =E2=80=9Cimmutable=E2=80=9D would have been a = better word choice than =E2=80=9Creadonly=E2=80=9D for conveying the = original intention. We could also ignore the original intention and = reinterpret the feature in case everyone agrees (personally, I prefer = the original intention, but I won=E2=80=99t fight for that). =E2=80=94Claude [1]: https://wiki.php.net/rfc/readonly_properties_v2#rationale --Apple-Mail=_C7A60B94-72D6-40FF-AD4C-FC77FF7A42C8 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 3 juil. 2024 =C3=A0 14:42, Rob Landers = <rob@bottled.codes> a =C3=A9crit :

On Wed, Jul 3, = 2024, at 14:28, Claude Pache wrote:


Le 3 juil. 2024 =C3=A0 11:54, Claude Pache = <claude.pache@gmail.com> a =C3=A9crit = :


2. As for readonly, I think that = the invariant it is supposed to provide should be enforced as strictly = as possible. It means that `readonly` is only acceptable if there is no = `get` hook.

Hi,

One more thing, why I think that we = should be strict here. It is not just for preventing the user to write = *dumb* code, it is also for preventing them to write *creative* code, = e.g.

```php
class doc = {
    public readonly int page = {
        get =3D> $this->page + = $this->offset;
    }
  =   private int $offset =3D 0;
    public = function __construct(int $page) {
      =   $this->page =3D $page;
    = }
    public function foo() = {
        // $this->offset may be = adjusted here
    = }
}
```

=E2=80=94= Claude

I don't see anything wrong with that code. $page = doesn't say "immutable" it says "readonly", as in "cannot write = to".

=E2=80=94 = Rob

The fact you = don=E2=80=99t see anything wrong is *precisely* the issue. According to = the original RFC [1], the intention of readonly properties was = immutability, not just non-writability. For the weaker case of = non-writability, it was explicitly mentioned the possibility of (future) = asymmetric property visibility.

That said, I = agree that =E2=80=9Cimmutable=E2=80=9D would have been a better word = choice than =E2=80=9Creadonly=E2=80=9D for conveying the original = intention. We could also ignore the original intention and reinterpret = the feature in case everyone agrees (personally, I prefer the original = intention, but I won=E2=80=99t fight for = that).

=E2=80=94Claude

[= 1]: = https://wiki.php.net/rfc/readonly_properties_v2#rationale



= --Apple-Mail=_C7A60B94-72D6-40FF-AD4C-FC77FF7A42C8--