Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122679 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 20AC91AD8F6 for ; Mon, 18 Mar 2024 09:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710753258; bh=Q03FwjSnevRkr/94YGq34jQyEpOgB5UobUvwqHnWIQk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QPAmLZ57UqsNRCLtk53R1+hRV3NN6nyeVw8jJO2KN/sDQWZtScfpN7lyEXawgyXQY 54zuQkWMzVphT2Xm5ZEjMsMqVgqD7TW3rCIxgVCZGBBcyg7lidyIHGU/usgh5PzTR1 g6M4jEnFQ1ubrT2F1OR28XYo7dnlRtPUe+uZoWMZLvSJ37PDvoUHyKXOfA+lyOcnG2 LJnU3F+R1Hp/f2tte0Dw/TXOgwx0gov9boQMtEQE6EhGd3IuWyj+AbEH8BqFwn5eJN WlQahx+yKCimDDn30+ogACTQyKdNItiuhdCqTmqLZYvpPpFOvMh34vHSlgL0TciMlc 13DrCnsquYYTw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE42E180080 for ; Mon, 18 Mar 2024 09:14:16 +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-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 ; Mon, 18 Mar 2024 09:14:16 +0000 (UTC) Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5687e7662a5so5532681a12.0 for ; Mon, 18 Mar 2024 02:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710753235; x=1711358035; 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=U4zPxRS9ZZEaAUlcxfSM7t1U9EASzvn29tQos6Q29i0=; b=My1LRtj8IDCEEn/8d/aQhemqMtTCOG0XSKpcFdoSaYD6AzAZyHteaZDFYjvTsTGsoe wanwN+M1q/wJmcv6xShfv1fAysTc40sZFgNLBBSDYEhz/JOaGB2t05+N9sBuTn1iAPjC Yyc/+JmxC6INKA19wExQ1QggDyFpBiBCVHzDSOnXOZh43y8kHIAJhecrg/21xY1DkIJD ohSbdAu98GeFO3izf1egkqqA4SPB9JjfO5w69AUwup1HT8NgFYG0/DCblWXc3IreImQt o0IpG3xs3g5602uKicflt38K0Rmr4vRyHBZt8RUcZxlq8YOPBMjcOzs801sjFRacZ591 v4Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710753235; x=1711358035; 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=U4zPxRS9ZZEaAUlcxfSM7t1U9EASzvn29tQos6Q29i0=; b=wGKY7VJNbjYRx9eVOJJ31e8EZ0QxHYpKRfVJnAskgZLhoozVisJrNJhS8Xf1v/XoTK rUoJ8zUZKU+dYwJmLWuUvvWPHyg8xcfo143eNjtm1TGUlA9xYKTiI7NvwdEwhKLg/Qm9 AIX4S8Zg0C/OEAb/+mzj1iZ7DgGOvpo2dXJkKQ+dCQxjOOwx5qPXUHCIrva6GQNqatHc dTfaoDPbAtxuja5zeboB4+xp2c7pigUTaSaILlQC52WG46+nZtA2OJCEARriN+MJ2U3m DGTGU7B8nwLrmk31YCD6IUpaRekCaeL4Tok6jAt9mBdLreQBALevgsTFA+bPKeoz993S bEew== X-Gm-Message-State: AOJu0YwjRGRJ/py2RW86J/fn0LxRpoi8wnODM3mXkPALxsXeTSQAh/nP CdZofkpM4Xk2KAY+pWl2HjG7babxoRR1ZZMDWJRZpSP+Fohe9CEuxIdbF7T3QzcdG+ddUw2zFMP aC+K/fcOq0YFPThm++aNnU0+Tc8gSfxh3Mng= X-Google-Smtp-Source: AGHT+IHG+bqnZbn623+9PnN5eGHtY5lqdN2RmVyzxdAfeWJew/3VRr/YVTKKYHvLI6eiR7qDhJDnb/Sw0RPM+K0DvU4= X-Received: by 2002:a05:6402:520f:b0:568:d303:74dc with SMTP id s15-20020a056402520f00b00568d30374dcmr2352230edd.38.1710753235111; Mon, 18 Mar 2024 02:13:55 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 18 Mar 2024 10:13:28 +0100 Message-ID: Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000e096100613ebc67f" From: kjarli@gmail.com (Lynn) --000000000000e096100613ebc67f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 21, 2024 at 7:58=E2=80=AFPM Larry Garfield wrote: > Hello again, fine Internalians. > > 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. > > 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. > > -- > Larry Garfield > larry@garfieldtech.com In regards to arrays, what about additional operations next to get/set? I doubt this solution will cover all the use-cases or perhaps even over-complicate things, just throwing the idea out there. ```php class Test { private array $_myData =3D []; public array $myData { get =3D> $this->_myData; append =3D> $this->_myData[] =3D $value; } } ``` Thinking about the other post about offset and containers ( https://github.com/Girgias/php-rfcs/blob/master/container -offset-behaviour.md): ```php class Test { private array $_myData =3D []; public array $myData { get =3D> $this->_myData; append =3D> $this->_myData[] =3D $value; write_dimension =3D> $this->_myData[$offset] =3D $value; } } ``` Is this issue restricted to arrays only? From my understanding objects functioning as arrays are already by reference and thus should not suffer from this? ```php class Test { private ArrayObject $_myData; public ArrayObject $myData { get =3D> $this->_myData; } public function __construct() { $this->_myData =3D new ArrayObject(); } } // would this work without issues? $obj =3D new Test(); $obj->myData[] =3D 'test'; ``` --000000000000e096100613ebc67f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Feb 21, 2024 at 7:58=E2=80=AF= PM Larry Garfield <larry@garfi= eldtech.com> wrote:
Hello again, fine Internalians.

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.

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.

--
=C2=A0 Larry Garfield
=C2=A0 larry@ga= rfieldtech.com

In regards to arrays, wh= at about additional operations next to get/set? I doubt this solution will = cover all the use-cases or perhaps even over-complicate things, just throwi= ng the idea out there.

```php
class Test= {
=C2=A0 =C2=A0 private array $_myData =3D [];
=C2=A0 = =C2=A0 public array $myData {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 get =3D= > $this->_myData;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 append =3D>= ; $this->_myData[] =3D $value;
=C2=A0 =C2=A0 }
}
```=C2=A0

=C2=A0Thinking about the other po= st about offset and containers (https://github.com/Girgias/php-rfcs/blob/master/container-offset-behaviour.md):
```php
class Test {
=C2=A0 =C2=A0 private array $_myData =3D [];<= /div>
=C2=A0 =C2=A0 public array $myData {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 get =3D> $this->_myData;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = append =3D> $this->_myData[] =3D $value;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 write_dimension =3D> $this-= >_myData[$offset] =3D $value;
=C2=A0 =C2=A0 }
}
```

Is this issue restricted to arrays only?= From my understanding objects functioning as arrays are already by referen= ce and thus should not suffer from this?
```php
class Test {
=C2=A0 =C2=A0 private ArrayObject=C2=A0$_myData;<= /div>
=C2=A0 =C2=A0 public ArrayObject=C2=A0$myData {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 get =3D> $this->_myData;
=C2=A0 =C2=A0= }

=C2=A0 =C2=A0 public function __construct() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 $this->_myData =3D new ArrayObject(= );
=C2=A0 =C2=A0 }
}

// would this work without issues?
$obj =3D new Test();
$obj->myData[] =3D 'test';
```

<= /div>
--000000000000e096100613ebc67f--