Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122448 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 CDD901ACEBF for ; Wed, 21 Feb 2024 23:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708556577; bh=qxjhEqQc7jKUHMHAEpULUK/HLfBa9o4MQKtU9slD8Rc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ROrd7FOJOW6AtLVZHzJikwY2G19BsCSpDoBYr/4Wbb5zFgHhXQjKzK1JhtWW7VD+D /eIZxH/NoKNS4jAnr16CZ0adJntWcsGEiuTg34uGqUSlbq6DcITHo0U78Qkk6D0Z9t gBdAe4eeSC8lxkjM2Do4B1UZkV8JcOx7v2wpb3o77gy1tFQPx+OfO02M8P9nm3Juls d7OqjWRr9aN/YxBOLXvipKHGrMdM4/rzH/1n4vRk69gB1CHcVlm0H77EkTCGbs9zVb Mb2+24Jb9xJALwnLp5tBO8D4lTJkd7ii5vJDAqqdXyZRrN5SUWP9/Z2pQUudAGvZHR mro7VkwtBTQ8A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 639CC1805DA for ; Wed, 21 Feb 2024 23:02:56 +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: No X-Envelope-From: Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (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, 21 Feb 2024 15:02:55 -0800 (PST) Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3bba50cd318so5364178b6e.0 for ; Wed, 21 Feb 2024 15:02:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708556570; x=1709161370; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2bzcd+egP8EihVRLcxFsgqtLzDWKXOw5XZT+Z2RkkVI=; b=f/mg2OdshBmzYzBssWG0OWWrHw+TW3qm/Y1nqF8Dkz321AwR3yJUTMU/ITIx+Zh483 apeoYSMZQ2dTI1urG2R73gJOENjdzCjMLhm+c0BG8KsAJbXRY5KHjT6S+3VjoIc84juz kJb/uAalcpohLu3K4fHOqKMlH1B5/5XrPcqZURnwLkNaez9zSMRLDtk6NRafaLtidceU dO9sG0QhiFy2DwaxYiBpaoefNXnMBkiT6Ev/SekeWbpjRummr7rZUbMSXmY2u3isDqwy os/69AsvxGU7d669yzT32L2vlbmtNDnz6KCPWUBmGw7gI6lfJ3t4ZitXgJO6K6CuK99S BIhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708556570; x=1709161370; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2bzcd+egP8EihVRLcxFsgqtLzDWKXOw5XZT+Z2RkkVI=; b=H1q6vGBK4REACgKJ0pV/taMQVM8rpWHmHIR/kZpSWE2zBAX+C1VsA8992B9itbqckj BQCZRLMr2c6Nj4flW36DN3eNCaDCK4K1ldaXS+uYZ7+bM1PQr4rrMfbLvtsY6QBPB7gR v+k9zUHdGYCxmlG2D7gZnFdTLwUlipopc/QriLdmHI5bbHkWxr+y8V5qDVP7XbXBuXgv G6gkqvookivkM/DFkx9LxTU/gfd9gWfMMX0A9+U0yzMsyXR8YHVGo4oS6xDoQcZPVrpy vnCPJEvv439YcBHaeO7QplUpC8OZjODjvIVBDX9WgqMZ8mmBEeKOR80m2TBcyUCr+es0 gK8g== X-Gm-Message-State: AOJu0YxI81+cdqOlNzHPWwPkw/Qs2wlUjgiYgVpAH67PpRl1IraEV0yd 6f580Cjb4Zv7hKmVWEycjTWK9yI7EbIeLW3gt+1mnbqr8AY1EWoK2w2dqXhcGcfknB3iZ3UASOl DL1fQ/Pxv5BePCj3k+Qk4SCCvWsFHtEss X-Google-Smtp-Source: AGHT+IEH+5Ij5vcjaQjEss80uxWiO2LuwFdJ+7Y2cNMkqqSCXkc3rIQwIV6NoERx5Zv760FBaSs921n5nsSTHD1UgTY= X-Received: by 2002:a05:6808:1442:b0:3c1:3215:1881 with SMTP id x2-20020a056808144200b003c132151881mr26113174oiv.7.1708556569884; Wed, 21 Feb 2024 15:02:49 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 21 Feb 2024 17:02:38 -0600 Message-ID: Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000006d3d010611ec5304" From: mweierophinney@gmail.com ("Matthew Weier O'Phinney") --0000000000006d3d010611ec5304 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 21, 2024 at 12:57=E2=80=AFPM Larry Garfield wrote: > After much on-again/off-again work, Ilija and I are back with a more > polished property access hooks/interface properties RFC. It=E2=80=99s 99= % > unchanged from last summer; the PR is now essentially complete and more > robust, and we were able to squish the last remaining edge cases. > > Baring any major changes, we plan to bring this to a vote in mid-March. > > https://wiki.php.net/rfc/property-hooks > > It=E2=80=99s long, but that=E2=80=99s because we=E2=80=99re handling ever= y edge case we could > think of. Properties involve dealing with both references and inheritanc= e, > both of which have complex implications. We believe we=E2=80=99ve identi= fied the > most logical handling for all cases, though. > Once again in reading the proposal, the first thing I'm struck by are the magic "$field" and "$value" variables inside accessors. The first time they are used, they're used without explanation, and they're jarring. Additionally, once you start defining the behavior of accessors... you don't start with the basics, but instead jump into some of the more esoteric usage, which does nothing to help with the questions I have. So, first: - Start with the most basic, most expected usage for each of reading and writing properties. - I need a better argument for why the $field and $value variables exist. Saying they're macros doesn't help those not deep into internals. As a user, why do they exist? Honestly, it's not obvious at all that I can just set something to the variable "$field", and if I didn't know about the feature and stumbled across a class that used accessors, I'd be wondering what "$field" is, and how the property ever gets set. (And yes, I've read the FAQ. Saying it's used in another language doesn't automatically make it good design.) I know you say in the narrative that you _can_ use `$this->propertyName =3D= ` to set the value, but you also say it's _not recommended_ (though you do not indicate _why_). To somebody coming primarily from userland who's been doing OOP in PHP for over 20 years, it's far more clear what's happening. Alternately, I'd argue that both the accessors should require an argument that represents the reference to the property: public string $username { set($field, string|Stringable $value) { $field =3D (string) $value; } get ($field) =3D> strtolower($field); } The same is true for $value. I'd recommend only ever allowing the construct `set ($value) {}`, as it's immediately clear that `$value` is the argument and value being provided to the accessor. When it's implicit, it's easy to lose context. Second: you don't have examples of defining BOTH get and set OTHER than when using expressions for both accessors or a mix. I'm actually unclear what the syntax is when both are defined. Is there supposed to be a `;` terminating each? Or a `,`? Or just an empty line? Again, this is one of the more common scenarios. It needs to be covered early, and clearly. Third: the caveats around usage with arrays... give me pause. While I'm personally trying to not use arrays as much as possible, a lot of code I see or contribute to still does, and the fact that an array property that uses a write accessor doesn't allow the same level of access as a normal array property is something I see leading to a lot of confusion and errors. I don't have a solution, but I worry that this one thing alone could be enough to prevent the passage of the RFC. Fourth: the syntax around inheritance is not intuitive, as it does not work in the same way as the rest of the language. I'm talking about this: public int $x { get: 2 * parent::$x::get() } Why do we need to use the accessors here? Why wouldn't it just be `parent::$x`? I want to be clear: I really like the idea behind this feature, and overall, I appreciate the design. From a user perspective, though, the above are things that I found jarring as they vary quite a bit from our current language design. > > Note the FAQ question at the end, which explains some design choices. > > There=E2=80=99s one outstanding question, which is slightly painful to as= k: > Originally, this RFC was called =E2=80=9Cproperty accessors,=E2=80=9D whi= ch is the > terminology used by most languages. During early development, when we ha= d > 4 accessors like Swift, we changed the name to =E2=80=9Chooks=E2=80=9D to= better indicate > that one was =E2=80=9Chooking into=E2=80=9D the property lifecycle. Howe= ver, later > refinement brought it back down to 2 operations, get and set. That makes > the =E2=80=9Chooks=E2=80=9D name less applicable, and inconsistent with w= hat other > languages call it. > > However, changing it back at this point would be a non-small amount of > grunt work. There would be no functional changes from doing so, but it=E2= =80=99s > lots of renaming things both in the PR and the RFC. We are willing to do = so > if the consensus is that it would be beneficial, but want to ask before > putting in the effort. > I personally would go with just "accessors". --=20 Matthew Weier O'Phinney mweierophinney@gmail.com https://mwop.net/ he/him --0000000000006d3d010611ec5304 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Feb 21, 2024 at 12:57=E2=80= =AFPM Larry Garfield <larry@ga= rfieldtech.com> wrote:
After much on-again/off-again work, Ilija and I are back with a more polish= ed property access hooks/interface properties RFC.=C2=A0 It=E2=80=99s 99% u= nchanged from last summer; the PR is now essentially complete and more robu= st, and we were able to squish the last remaining edge cases.

Baring any major changes, we plan to bring this to a vote in mid-March.

https://wiki.php.net/rfc/property-hooks

It=E2=80=99s long, but that=E2=80=99s because we=E2=80=99re handling every = edge case we could think of.=C2=A0 Properties involve dealing with both ref= erences and inheritance, both of which have complex implications.=C2=A0 We = believe we=E2=80=99ve identified the most logical handling for all cases, t= hough.

Once again in reading the propos= al, the first thing I'm struck by are the magic "$field" and = "$value" variables inside accessors. The first time they are used= , they're used without explanation, and they're jarring.
=
Additionally, once you start defining the behavior of access= ors... you don't start with the basics, but instead jump into some of t= he more esoteric usage, which does nothing to help with the questions I hav= e.

So, first:

- Start wit= h the most basic, most expected usage for each of reading and writing prope= rties.
- I need a better argument for why the $field and $value v= ariables exist. Saying they're macros doesn't help those not deep i= nto internals. As a user, why do they exist?

Hones= tly, it's not obvious at all that I can just set something to the varia= ble "$field", and if I didn't know about the feature and stum= bled across a class that used accessors, I'd be wondering what "$f= ield" is, and how the property ever gets set. (And yes, I've read = the FAQ. Saying it's used in another language doesn't automatically= make it good design.)=C2=A0

I know you say in the= narrative that you _can_ use `$this->propertyName =3D ` to set the valu= e, but you also say it's _not recommended_ (though you do not indicate = _why_). To somebody coming primarily from userland who's been doing OOP= in PHP for over 20 years, it's far more clear what's happening. Al= ternately, I'd argue that both the accessors should require an argument= that represents the reference to the property:

= =C2=A0=C2=A0=C2=A0 public string $username {
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 set($field, string|Stringable $value) {
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $field = =3D (string) $value;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 }
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 get ($field) =3D= > strtolower($field);
=C2=A0=C2=A0=C2=A0 }
<= br>
The same is true for $value. I'd recommend only ever allo= wing the construct `set ($value) {}`, as it's immediately clear that `$= value` is the argument and value being provided to the accessor. When it= 9;s implicit, it's easy to lose context.

Secon= d: you don't have examples of defining BOTH get and set OTHER than when= using expressions for both accessors or a mix. I'm actually unclear wh= at the syntax is when both are defined. Is there supposed to be a `;` termi= nating each? Or=C2=A0 a `,`? Or just an empty line? Again, this is one of t= he more common scenarios. It needs to be covered early, and clearly.

Third: the caveats around usage with arrays... give = me pause. While I'm personally trying to not use arrays as much as poss= ible, a lot of code I see or contribute to still does, and the fact that an= array property that uses a write accessor doesn't allow the same level= of access as a normal array property is something I see leading to a lot o= f confusion and errors. I don't have a solution, but I worry that this = one thing alone could be enough to prevent the passage of the RFC.

Fourth: the syntax around inheritance is not intuitive, as= it does not work in the same way as the rest of the language. I'm talk= ing about this:

=C2=A0=C2=A0=C2=A0 public int $x {=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 get: 2 * parent::$x::= get()
=C2=A0=C2=A0=C2=A0 }

Why do we nee= d to use the accessors here? Why wouldn't it just be `parent::$x`?

I want to be clear: I really like the idea behind this= feature, and overall, I appreciate the design. From a user perspective, th= ough, the above are things that I found jarring as they vary quite a bit fr= om our current language design.

Note the FAQ question at the end, which explains some design choices.

There=E2=80=99s one outstanding question, which is slightly painful to ask:= Originally, this RFC was called =E2=80=9Cproperty accessors,=E2=80=9D whic= h is the terminology used by most languages.=C2=A0 During early development= , when we had 4 accessors like Swift, we changed the name to =E2=80=9Chooks= =E2=80=9D to better indicate that one was =E2=80=9Chooking into=E2=80=9D th= e property lifecycle.=C2=A0 However, later refinement brought it back down = to 2 operations, get and set.=C2=A0 That makes the =E2=80=9Chooks=E2=80=9D = name less applicable, and inconsistent with what other languages call it.
However, changing it back at this point would be a non-small amount of grun= t work. There would be no functional changes from doing so, but it=E2=80=99= s lots of renaming things both in the PR and the RFC. We are willing to do = so if the consensus is that it would be beneficial, but want to ask before = putting in the effort.

I personally wou= ld go with just "accessors".


--
=
he/him
--0000000000006d3d010611ec5304--