Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123564 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 333AF1A009C for ; Sun, 9 Jun 2024 16:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1717952038; bh=yyWCirWhsSjIZwy8Jjh2xg5pOpF181ARN7fYiOI1oxQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=neTwsN4702lXny87M/ZPdV2eb2cDw2m7Qv8EWzupZiFCxFOCaaxx39JrqMz2yz+ql LT8x57haEbc7gcl3bmD6uofTCIrk55pJTceRwNcOIuPxUzKUGtF881Q4WISzQqYvg1 GRI8ZPrYA+ys9uASVO96QNeT3BT2wZs1qFqO81ChK14h8nvDsFbxHsHhG2ZdOWMzwc 7mXkQoxGfBv75R0AKtnNM1+K9rwZJv7IHAeTDsjk1StIveJ67je3WN0uzLZddHhTKR vgzR0djuIGBqYSs72Fu7O/VOAEsUuVgpe5uVnnL9/EubFFz82s0/cn6dYCjZgevQZQ +s5rHXWLcOYnQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ECA5F180003 for ; Sun, 9 Jun 2024 16:53:57 +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-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) (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 ; Sun, 9 Jun 2024 16:53:57 +0000 (UTC) Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-80b7f0910cbso562342241.2 for ; Sun, 09 Jun 2024 09:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717951969; x=1718556769; 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=yyWCirWhsSjIZwy8Jjh2xg5pOpF181ARN7fYiOI1oxQ=; b=gA5tRBxNO6SU/HLxHAO540yOrBT1R/H9Kr/NdBFfZ3Iz8124ZNWxTtzAw0lxhKgT08 Pi5AOcTig/kfHT98anQo2BPGJ4XhSC5f7I/7K5KYPNyZR0hC2MgZU15O4CqKWoZvbNG8 XsTntVUisEEUZ6uyQhibv1LvQu7CZy1EtwoYqspRJ0lseH/m2Njg3w66NxiLzQCbdsKa 2HCaxcOLd3sMXrqD2j+XANToN3wZThsu5JrDJQ2bVMWnS7wtRcs7j/TDG38AxHBGwC/7 +HLbDTsJUaWx4pQa8Gb0Fmh40oGtrQvlefIqOJIl68hmgdzN33zl42qjtfIoQn0R9vir SnBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717951969; x=1718556769; 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=yyWCirWhsSjIZwy8Jjh2xg5pOpF181ARN7fYiOI1oxQ=; b=n1DKGycnF33iUe/qmNC/hex4dCukXDAVPu83r1lhiuq9VGvlKXac9PINpWwKudeBlt rwhyXe3LESAyFp8WPphUROAjtWRBTafSvpCnbZzFHV6u6Rb85VZC2nvOyd9RLHzPh8tq r9zRF9Zx287KxMJ5hsVdUjfSN57PCBB+mX+JKy8zcFtb36OzqwHOMXGxyFH/QIcwBfe5 fXIbqXz2ogkKfJloUCLHVypk0OChwZrw7KQ49/CuO7T053L8A0ZpqaY22nLo8EvjZL2c rDlTj4MgVT+TaRPQ2CwAHKYT8i4EcZZ+DQB9JqGaXxPCGsPxuKjy01CnGnIhkevGrret TQ0A== X-Forwarded-Encrypted: i=1; AJvYcCVYvCKyHeGUOOaZF1kcv3mWnkdoZ8kxXVhlTCroDm++x/hWltcMjY/9VVdvbhYUG5v3vh/QcUZfRHPmcBpQ/rGeHV+h2WDeEA== X-Gm-Message-State: AOJu0YztqHJwyaArqzfpBh8OgVTqzcYciQWeOp1AoAESBnmLROwF/JE5 /VttXEAkjtvERqLUVJ0JD1iX4eVodtmaZU/gtFj+J1xUeBHp78Q1Ln3EDDVctdtgvQgCIU5Wqa8 LlJmK1iyyn4alqvW0OZI4CGBtmzA= X-Google-Smtp-Source: AGHT+IGf+45VdJTJXwAgKLRi1VF4oxbWkTnwZ/CqJIxzeDzVtA+wjVPBWE1m+e9aCCii4MS16/b96Se0p7t0oyQJV7o= X-Received: by 2002:a05:6102:3569:b0:48c:47c3:7858 with SMTP id ada2fe7eead31-48c47c37c96mr2395645137.29.1717951969634; Sun, 09 Jun 2024 09:52:49 -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: Sun, 9 Jun 2024 10:52:38 -0600 Message-ID: Subject: Re: [PHP-DEV] [RFC][Vote] Property Hooks To: Nikita Popov Cc: Larry Garfield , PHP internals Content-Type: multipart/alternative; boundary="000000000000e432f8061a77dc7e" From: lnearwaju@gmail.com (Lanre) --000000000000e432f8061a77dc7e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Personally I still think we should have used TS/JS syntax for computed properties. PHP is much closer to typescript than Java/C# and we already have support for modifiers. Slightly more verbose but these issues would be non-existent. On Sun, Jun 9, 2024 at 10:03=E2=80=AFAM Nikita Popov wrote= : > 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. > > > I know I'm a few months late on this one, but I figured I'd still leave a > couple of thoughts... Overall, the proposal is well thought out and does > address many of the reservations I had about my original accessors propos= al. > > One of the more interesting choices in this proposal is to base whether > the property is virtual or backed on the presence of a "$this->prop" > reference in the accessor implementation. I think that, conceptually at > least, this is a good choice. > > What I find concerning though, is that the presence/absence of such a > reference also affects the meaning of the get and set hooks. If the > property is virtual and it only has get, then the property cannot be set. > If the property is backed and only has get, then the property *can* be se= t. > A no-op setter is implied. (Similar for only having a set hook.) > > This has the unfortunate consequence that you actually have to look at th= e > accessor implementation to determine the API of the class -- only looking > at the "prototypes" (i.e. signatures without implementation bodies) is no > longer sufficient! This seems both unfortunate and unprecedented. > > This could have been avoided by still requiring an explicit no-op "set;" > at the expensive of some additional verbosity. > > 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 > --000000000000e432f8061a77dc7e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Personally I still think we should have u= sed TS/JS syntax for computed properties. PHP is much closer to typescript= =C2=A0than Java/C# and we already have support for modifiers. Slightly more= verbose but these issues would be non-existent.

On Sun, Jun 9, 2024 at 10:0= 3=E2=80=AFAM Nikita Popov <php@npopov.= com> wrote:
On Mon, Apr 15, = 2024, at 18:43, Larry Garfield wrote:
The vote for the Property Hooks RFC is n= ow open:



I know I'= ;m a few months late on this one, but I figured I'd still leave a coupl= e of thoughts... Overall, the proposal is well thought out and does address= many of the reservations I had about my original accessors proposal.

One of the more interesting choices in this proposa= l is to base whether the property is virtual or backed on the presence of a= "$this->prop" reference in the accessor implementation. I thi= nk that, conceptually at least, this is a good choice.

What I find concerning though, is that the presence/absence of suc= h a reference also affects the meaning of the get and set hooks. If the pro= perty is virtual and it only has get, then the property cannot be set. If t= he property is backed and only has get, then the property *can* be set. A n= o-op setter is implied. (Similar for only having a set hook.)

This has the unfortunate consequence that you actually have= to look at the accessor implementation to determine the API of the class -= - only looking at the "prototypes" (i.e. signatures without imple= mentation bodies) is no longer sufficient! This seems both unfortunate and = unprecedented.

This could have been avoided by= still requiring an explicit no-op "set;" at the expensive of som= e additional verbosity.

The other thing that s= tood out to me are the short-hand notations using =3D>. There was a prio= r RFC on the topic (https://wiki.php.net/rfc/short-functions), which has be= en declined. That RFC would have introduced =3D> ... as a general shorth= and for { return ...; }.

The shorthand notatio= n for get is compatible with that formulation. However, the shorthand notat= ion 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 r= evisiting a general short function syntax in the future. Mostly I'm scr= atching 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 short= hand. The common case is a guard that checks the value without modifying it= .

Putting this to the "would this shortha= nd have passed if it were introduced by a separate RFC on top of the base i= mplementation" test, I think the answer would have been a clear "= no".

Regards,
Nikita
--000000000000e432f8061a77dc7e--