Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123565 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 143D91A009C for ; Mon, 10 Jun 2024 12:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718022880; bh=XdaLhfWfCMpQFQY9uc4TTcybCd+aXBRy7dewN4OU/W8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RH5eJv88gICR/vqnGPcUiFYXzD919RP7viJwm1WDDG977fBY3h6EtiZNda5qJ5qR2 BOssAXNPNW02detseqaDT0hoYz4qh/Y97IWv7erUtQ2rEscnp1HRjncnKTJs8fWqOH PhFLfg1BLVh/OHXpHoR6W1t1ZN6iSA4du6L3ZMKBVnMdVjdjnbcruvJdwbZe9D7NRF 0grDMVNqAOKkzkAchXZo2U106two9YNk/Zcj4WsmsskYI0EIR8c4XSs9L4sd5N8803 O/67qbJlDtKYWjSg4EbLipXaHr6Xrw3OiV7jsQS6gTI7vz2tguZYdXC820nK/+3xG6 d1nJmRqOIx7tQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 80DAA180003 for ; Mon, 10 Jun 2024 12:34:39 +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-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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, 10 Jun 2024 12:34:39 +0000 (UTC) Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-52bd48cf36bso2973984e87.3 for ; Mon, 10 Jun 2024 05:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718022810; x=1718627610; 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=NAlYZmK+aX98D1dwzOdewG0agC8X0g7gkefDSN9eTx0=; b=HKgbHGsPuArfpDmtdcroesGT1vvTG4AVj4js69U8hU6NHiXWAVLSQX9Wml82fXlWSo yIbu7CHtkD+ud3gPOABGurXHAOt3OJxsA1kJYyoMTRc/Ki24zeKQUT6jKtwDbqQQr/52 KxmId+iRPCXbzwdVkBBxznONhfhm/Gjv3D/wsj36Vr0Bw1PUmA/HYqHY6odTp+QbWdPn QwfOwQ7hzt4gF+o2PDg/gK8rukUCRCHa4sEZBMPtEUbuG/jUNHs5+7EgXcA6ffofhPko +j6YMeFp8OmWv1WtqfDEMearKk4Oe+NJyK5gb+HkuRSmg0dDzx4Rm6QFTOJfQPIEmlI/ B6fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718022810; x=1718627610; 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=NAlYZmK+aX98D1dwzOdewG0agC8X0g7gkefDSN9eTx0=; b=tGKjvbzBmmcEHpeKSUK+6H6rb2FNic7NFGHy6JWX+X0M2KUsexoKikQB6zkK2rhf3W +QZy0QtM/F9GrQOPU9lp0e3I4dizhGB1LWLggS7XgLqraAazfu0r+49JaNzBC5JZEfBj alqGPrVEvEbLR5yjxEkjoJ6LQUR07cNlUVBTGj9GNtmrOX6hHvWan8iPfnQrMmINUVjV a47sAQCNlfGDzgzvw09bZXkpLC4RAqCtNZBEEPnXjdzfjoWOtN+x/rzD61GRById3WmM v62GH/ff9q3SkTi3kN1mHzHQE8J2PIN1mFrj6u7yY5gk9ywXunuw6DqK712NM6acyOCg 5TGg== X-Forwarded-Encrypted: i=1; AJvYcCW3qCaxLeM8a9WikSkI6eDE0QMYBkMANVaxsZ3C2t8JlHLPvrxP3hkjl4fpST2wSG6n81nrkpjb2VC+vj2yc91pGXkJVVd3yQ== X-Gm-Message-State: AOJu0YwTd04uQFxdnhqUUObuMg+R4GpffXN2C1qsdaqNBb+5FD4U8p/A EVPmddlp2cNnPC3rV25iFCzIPp1RoI7fcRGReTds+6YnXeZkPryZCNsfSXLvQsJq71t9xg4Wana 4Bxt4rB9JF+YH2zjn8DfwzGnxXg== X-Google-Smtp-Source: AGHT+IFncTkMJv3nFiAFKGW36oo70XB6xF4L9XNk107mkJzTPUVXb5i2HsK6QSC9I8W2AlQgR/iE2DLkswIgRJEwK9o= X-Received: by 2002:a05:6512:3f14:b0:529:ed29:dc94 with SMTP id 2adb3069b0e04-52bb9fcc165mr6891656e87.44.1718022809791; Mon, 10 Jun 2024 05:33:29 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <834cb6c7-c6ae-4b59-b022-a43793f842a3@app.fastmail.com> In-Reply-To: <834cb6c7-c6ae-4b59-b022-a43793f842a3@app.fastmail.com> Date: Mon, 10 Jun 2024 15:33:18 +0300 Message-ID: Subject: Re: [PHP-DEV] [RFC][Vote] Property Hooks To: Nikita Popov Cc: Larry Garfield , PHP internals Content-Type: multipart/alternative; boundary="0000000000004b37ed061a885bfe" From: udaltsov.valentin@gmail.com (Valentin Udaltsov) --0000000000004b37ed061a885bfe Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sunday, 9 June, 2024=E2=80=AFat 19:03, Nikita Popov wro= te: > On Mon, Apr 15, 2024, at 18:43, Larry Garfield wrote: > > The vote for the Property Hooks RFC is now open: > > https://wiki.php.net/rfc/property-hooks > > Voting will close on Monday 29 April, afternoonish Chicago time. > > > The other thing that stood out to me are the short-hand notations using > =3D>. There was a prior RFC on the topic ( > https://wiki.php.net/rfc/short-functions), which has been declined. That > RFC would have introduced =3D> ... as a general shorthand for { return ..= .; }. > > The shorthand notation for get is compatible with that formulation. > However, the shorthand notation for set is not. In that case =3D> ... isn= 't > short for { return ...; }, but rather for { $this->prop =3D ...; }. > > This seems pretty unfortunate to me, and possibly closes the door on > revisiting a general short function syntax in the future. Mostly I'm > scratching my head at why this was included in the proposal at all, as I > would not expect this use of the set hook to be common enough to justify = a > shorthand. The common case is a guard that checks the value without > modifying it. > > Putting this to the "would this shorthand have passed if it were > introduced by a separate RFC on top of the base implementation" test, I > think the answer would have been a clear "no". > > Regards, > Nikita > Correct me if I'm wrong, but here's how I understand the short-hand notation in setter hook in combination with https://wiki.php.net/rfc/short-functions: ``` final class Foo { // Before public string $x { set { $this->x =3D $this->transformX($value); } } private function transformX(string $value): string =3D> trim($value); // After public string $x { set =3D> trim($value); } } ``` So it's kinda consistent if you say that only the right side of the property assignment is replaced with short-hand notation, not the whole assignment. And then `$this->x =3D` is implicit. --=20 Regards, Valentin --0000000000004b37ed061a885bfe Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sunday, 9 June, 2024=E2=80=AFat 19:03,= Nikita Popov <php@n= popov.com> wrote:
On Mon, Apr 15, 2= 024, at 18:43, Larry Garfield wrote:
The vote for the Pr= operty Hooks RFC is now open:


Voting will close on Mo= nday 29 April, afternoonish Chicago time.

The other thing that stood out to me are the short-hand notations = using =3D>. There was a prior RFC on the topic (https://wiki.php.net/rfc/sho= rt-functions), which has been declined. That RFC would have introduced = =3D> ... as a general shorthand for { return ...; }.

<= /div>
The shorthand notation for get is compatible with that formulatio= n. However, the shorthand notation for set is not. In that case =3D> ...= isn't short for { return ...; }, but rather for { $this->prop =3D .= ..; }.

This seems pretty unfortunate to me, an= d possibly closes the door on revisiting a general short function syntax in= the future. Mostly I'm scratching my head at why this was included in = the proposal at all, as I would not expect this use of the set hook to be c= ommon enough to justify a shorthand. The common case is a guard that checks= the value without modifying it.

Putting this = to the "would this shorthand have passed if it were introduced by a se= parate RFC on top of the base implementation" test, I think the answer= would have been a clear "no".

Regar= ds,
Nikita

Correc= t me if I'm wrong, but here's how I understand the short-hand notat= ion in setter hook in combination with=C2=A0https://wiki.php.net/rfc/short-func= tions:

```
final class Foo
{
=C2=A0 =C2=A0 // B= efore
=C2=A0 =C2=A0 public string $x {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 se= t {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $this->x =3D $this->= transformX($value);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 }
=
=C2=A0 =C2=A0 private function transformX(string $value): string =3D>= ; trim($value);

=C2=A0 =C2=A0 // After
=C2=A0 =C2=A0 public strin= g $x {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 set =3D> trim($value);
=C2=A0 = =C2=A0 }
}
```

So it's kinda consistent = if you say that only the right side of the property=C2=A0assignment is replaced with short-hand= notation, not the whole assignment. And= then `$this->x =3D` is implicit.

--
Regards,
Valentin
--0000000000004b37ed061a885bfe--