Re: [RFC] Property hooks, nee accessors
| From: | Larry Garfield | Date: | Tue, 09 May 2023 22:59:43 +0000 |
| Subject: | Re: [RFC] Property hooks, nee accessors | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120223@lists.php.net to get a copy of this message | ||
On Tue, May 9, 2023, at 5:46 PM, Larry Garfield wrote:
>> I have a bigger concern: the take on references contradicts with the intro
>> about BC breaks: turning a materialized property into virtual one would
>> break BC as far as refs are concerned. One idea to fix that: add a ref
>> hook, that must return a reference. If not implemented => Error when trying
>> to get-by-ref. This could also help solve the $foo->array[] case (including
>> the asym-visiblity issue).
>
> That might be possible. The issue there is that the returned ref would
> still be bypassing the get/set hooks, so you're just adding a way to
> dance around the existing hook implementations, which is exactly what
> we're trying to avoid. Also, what would that hook even mean if used on
> a virtual property?
>
> Moreover, in practice, getting a reference to a property is extremely
> rare, with the exception of array writes. I cannot recall the last
> time I even saw some code get a reference to a property. That's why we
> felt comfortable just leaving it at is. In an earlier version of the
> RFC we had a way for properties to just disable references without
> adding any hooks, but removed it on the grounds that it was not worth
> the effort.
Addendum here: The RFC wasn't clear, in part because I wasn't clear, but the prohibition
on [] on properties applies only on set. On get, whatever array value is returned from the hook is
just a boring array, which can then be dereferenced to look up a key.
I've updated the RFC accordingly to make it clearer what is and isn't allowed with arrays.
--Larry Garfield