Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122613 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 8BEA01AD8F6 for ; Mon, 11 Mar 2024 16:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710176336; bh=TInKzGUHL6orUMo3LrVzdshM5Ewnnw6NfRVqBPNRrlI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RpItrPEadNd3AiRfnl3fo+qqD7lFEtOTe+QOdA1qP4g4YR3QZU/IViUDgBdp3D8O+ FAin2iAU3ZWARx4/CjYiv77EJROJhdQMnhHkotLGXsKS97KIkzNPmgc4+YyG15KDXo rmF+/YUFL3aJAxQ0rJFxszVlruJsXC8xGyipLTyokE+Ml3LcOtf6eCxK8YjEQtoidP Wlmy7kNFqxWU3bRbSjuIj9vOHolXe30Di6U16yRAOBJGuy5IvBT5ooR/j7ongqmzgd m3CjTGtmORSzgOoIyu91OMs3j6Fyn0qfkzVQC5+rrFmh5d9pqydHVW28cknJI7OjFr gEf5/YyaleZ0w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 007AC180825 for ; Mon, 11 Mar 2024 16:58: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.2 required=5.0 tests=BAYES_20,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-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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, 11 Mar 2024 16:58:55 +0000 (UTC) Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-dcc80d6004bso4459416276.0 for ; Mon, 11 Mar 2024 09:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710176318; x=1710781118; 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=0vdxC0HBz+7MT4HVP8PZz8xMClCE7hqqQcXzZMrCsNE=; b=KFu46/XCTCND4RAXwk2+kEGsEYcFOVDv3RhwC6s57XfeN20xgZ4U/EW//A39M8ly3w uf16ouadicIaBndmZ9D1gsZYGMUyB/+CUv9oiTiMbGuEOpJCh5eX9yeib0qvIkRL4HX2 hz7Z4ksoWt+CmU6UDvO5noWinRMHVHyuGVz255IVTInFBq2ZB+C7ma6Wy4uNPQa6veUE L4X5Fb6kucwx2vTFDFfv02MH2RuuK3j/kfQCuvN07cEvGbHyRy8aoh2PjlIc3WNq9CoS IGsNTzjzH8O6SiDZPdVIpLPBZEW5D7u/gGjGklgb0FpiH/sGdvEq9h4mo9UqXEvRkqaW joHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710176318; x=1710781118; 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=0vdxC0HBz+7MT4HVP8PZz8xMClCE7hqqQcXzZMrCsNE=; b=lE5Qqh1R1k+9XtlWdvo/QTnfCcMTknN0QfZi2uBoM+DM+Bm18DrrDqZ/nxHZrwxF/Y QgzCQGarufUax3Eb5l5wXb+nUEPaQ/bckMO+1VOKE8uofPUa/qvnJpbx1veek7hZNISc hWf/EHVarl0irXthLo1vc+5EjbShPy0TOR9wDLSt7Ju4BxRa81wFPxW+ki52BtBPxLXZ iOoGWpE9t73q1jm+zYdbBiYUbbYR/fqJJemjOvPONAIw3B08RZodswvrK6pSsmbZL1cr EPYYDgC9gFODbG9nw1yZXuzSljmw9nTCKy3Ft4/X7TfUqtoD8WhOQtaw4YWunAAok344 gH/A== X-Gm-Message-State: AOJu0YxBdl9SnkpsKXX9tiy3coujJfvYrLGtPyVF4V3ZMUeC7Ky7SxJJ p9rfT7xBX/olmHZHCvwyNzEP0lgHJK6TGOhNrscWGBnmzUnxXz/nPE2+az8dcbdExAU4b//RlYs lh95HP0pI7mhlcidZ5wNRJBhPdFA= X-Google-Smtp-Source: AGHT+IH5i9rQbn92GbieGSC9pxk5ITbn1/Q4qh1y3t1/jw/zbk8cpUEAB4Zh3/cmz1/ICVrmy9xN0YgqkIL+EHiA13g= X-Received: by 2002:a25:bb09:0:b0:dcc:f3fe:19c with SMTP id z9-20020a25bb09000000b00dccf3fe019cmr4760011ybg.59.1710176318473; Mon, 11 Mar 2024 09:58:38 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <84adc38a-210e-4f21-9145-0c99ae8c56f2@app.fastmail.com> In-Reply-To: <84adc38a-210e-4f21-9145-0c99ae8c56f2@app.fastmail.com> Date: Mon, 11 Mar 2024 17:58:26 +0100 Message-ID: Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000f74e710613657323" From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000f74e710613657323 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable pon., 11 mar 2024 o 15:30 Larry Garfield napisa=C5=82(a): > On Mon, Mar 11, 2024, at 8:35 AM, Micha=C5=82 Marcin Brzuchalski wrote: > > Hi Larry, > > > > pt., 8 mar 2024 o 16:55 Larry Garfield > napisa=C5=82(a): > >> Hi folks. Based on earlier discussions, we've made a number of change= s > to the RFC that should address some of the concerns people raised. We al= so > had some very fruitful discussions off-list with several developers from > the Foundation, which led to what we feel are some solid improvements. > >> > >> https://wiki.php.net/rfc/property-hooks > >> > > > > This RFC looks awesome, thanks Larry and Ilija I love the functionality > > in its current shape. > > > >> Thank you everyone for the feedback so far, and if you still have some= , > please say so. (Even if it's just to say that you're happy with the RFC > now so we feel more comfortable bringing it to a vote.) > > > > The only thing I don't like and can still be worked on is the > > reflection mechanism changes. > > The proposed methods isVirtual and getRawValue, setRawValue pair > > introduces a need to catch exceptions which could be eliminated by > > subtyping ReflectionProperty. > > Having these methods on a separate subtype allows returning a valid > > value. > > I realize this isn't trivial because for the last 2 days, I was > > thinking about giving it a name and TBH cannot figure out anything > > feasible. > > If this is not possible to put in understandable words then at least > > mention it in FAQ and why not. > > > > Cheers, > > Micha=C5=82 Marcin Brzuchalski > > Hm, interesting. I'll have to check with Ilija on feasibility. My > question is, how would it eliminate it? > > Suppose we hypothetically have a "ReflectionPropertyWithHooks" reflection > object. It has those three extra methods on it. But that means > $rObject->getProperty() could return a ReflectionProperty or > ReflectionPropertyWithHooks, and you don't know which it is. You'd have = to > do an instanceof check to know which type of property it is, and thus wha= t > methods are available. That doesn't seem any less clumsy (nor more, to b= e > fair) than calling isVirtual(). It is similar when you work with ReflectionType or ReflectionEnum, you always need to match against a certain type to ensure the code will behave predictably. > $rProp =3D $rObject->getProperty('foo', $obj); > $rProp->getValue(); // works always. > > if (!$rProp->isVirtual()) { > $rProp->getRawValue(); // Works, may or may not be the same return as > getValue() > } > > vs. > > if (!$rProp instanceof VirtualProperty) { > $rProp->getRawValue(); // Works. > } > > That doesn't seem to be an improvement. If you omit the conditional, you > still need a catch one way or the other. It just changes what gets throw= n > (an Exception vs an Error). What type of hierarchy were you thinking of > that would help here? > My thinking was like: 1. if the property has hooks, only then calling getRawValue, setRawValue, or isVirtual make sense, 2. if the property has no hooks and is static calling getRawValue, or setRawValue always throws because of "On a static property, this method will always throw an error." 3. if the property is "virtual", calling getRawValue, or setRawValue always throws an error, 4. if the property is not "virtual", calling getValue, or setValue is safe and never throws, otherwise it may throw under some conditions related to certain hook presence. In conclusion, I thought that the presence of hooks introduces 3 new methods but some will always be thrown because of incorrect usage. Normally, I'd model it with subtypes to completely avoid try-catch blocks for the cost of a simple instanceof check which I consider much cleaner for the reader than a bunch of try-catch blocks. Remember about static analysis, each of them when checked will propose to handle possible exceptions. But as wrote before, I don't know how to model it well. Cheers, Micha=C5=82 Marcin Brzuchalski --000000000000f74e710613657323 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
pon., 11 mar 2024 o 15:30=C2=A0Larry = Garfield <larry@garfieldtech.c= om> napisa=C5=82(a):
On Mon, Mar 11, 2024, at 8:35 AM, Micha=C5=82 Marcin Brzuchalsk= i wrote:
> Hi Larry,
>
> pt., 8 mar 2024 o 16:55 Larry Garfield <larry@garfieldtech.com> napisa=C5= =82(a):
>> Hi folks.=C2=A0 Based on earlier discussions, we've made a num= ber of changes to the RFC that should address some of the concerns people r= aised.=C2=A0 We also had some very fruitful discussions off-list with sever= al developers from the Foundation, which led to what we feel are some solid= improvements.
>>
>> https://wiki.php.net/rfc/property-hooks
>>
>
> This RFC looks awesome, thanks Larry and Ilija I love the functionalit= y
> in its current shape.
>
>> Thank you everyone for the feedback so far, and if you still have = some, please say so.=C2=A0 (Even if it's just to say that you're ha= ppy with the RFC now so we feel more comfortable bringing it to a vote.) >
> The only thing I don't like and can still be worked on is the
> reflection mechanism changes.
> The proposed methods isVirtual and getRawValue, setRawValue pair
> introduces a need to catch exceptions which could be eliminated by > subtyping ReflectionProperty.
> Having these methods on a separate subtype allows returning a valid > value.
> I realize this isn't trivial because for the last 2 days, I was > thinking about giving it a name and TBH cannot figure out anything > feasible.
> If this is not possible to put in understandable words then at least <= br> > mention it in FAQ and why not.
>
> Cheers,
> Micha=C5=82 Marcin Brzuchalski

Hm, interesting.=C2=A0 I'll have to check with Ilija on feasibility.=C2= =A0 My question is, how would it eliminate it?

Suppose we hypothetically have a "ReflectionPropertyWithHooks" re= flection object.=C2=A0 It has those three extra methods on it.=C2=A0 But th= at means $rObject->getProperty() could return a ReflectionProperty or Re= flectionPropertyWithHooks, and you don't know which it is.=C2=A0 You= 9;d have to do an instanceof check to know which type of property it is, an= d thus what methods are available.=C2=A0 That doesn't seem any less clu= msy (nor more, to be fair) than calling isVirtual().=C2=A0

It is similar when you work with ReflectionType or Reflecti= onEnum, you always need to match against a certain type to ensure the code = will behave predictably.
=C2=A0
$rProp =3D $rObject->getProperty('foo', $obj);
$rProp->getValue(); // works always.

if (!$rProp->isVirtual()) {
=C2=A0 =C2=A0 $rProp->getRawValue(); // Works, may or may not be the sam= e return as getValue()
}

vs.

if (!$rProp instanceof VirtualProperty) {
=C2=A0 $rProp->getRawValue(); // Works.
}

That doesn't seem to be an improvement.=C2=A0 If you omit the condition= al, you still need a catch one way or the other.=C2=A0 It just changes what= gets thrown (an Exception vs an Error).=C2=A0 What type of hierarchy were = you thinking of that would help here?

M= y thinking was like:
1. if the property has hooks, only then call= ing getRawValue, setRawValue, or isVirtual make sense,
2. if the = property has no hooks and is static calling getRawValue, or setRawValue alw= ays throws because of "On a static property, this method will always t= hrow an error."
3. if the property is "virtual", c= alling getRawValue, or setRawValue always throws an error,
4. if = the property is not "virtual", calling getValue, or setValue is s= afe and never throws, otherwise it may throw under some conditions related = to certain hook presence.

In conclusion, I tho= ught that the presence of hooks introduces 3 new methods but some will alwa= ys be thrown because of incorrect usage.
Normally,=C2=A0I'd m= odel it with subtypes to completely avoid try-catch blocks for the cost of = a simple instanceof check which I consider much cleaner for the reader than= a bunch of try-catch blocks. Remember about static analysis, each of them = when checked will propose to handle possible exceptions.

But as wrote before, I don't know how to model it well.

Cheers,
Micha=C5=82 Marcin Brzuchalski
--000000000000f74e710613657323--