> From: nicolas.gre...@gmail.com <nicolas.gre...@gmail.com> On Behalf Of
> Nicolas Grekas
> Sent: Thursday, June 21, 2018 16:08
> To: Nikita Popov <nikita....@gmail.com>
> Cc: PHP internals <internals@lists.php.net>
> Subject: Re: [PHP-DEV] [RFC] Typed Properties
> 
> Hi Nikita, Bob,
> 
> I anticipate one case on Symfony VarDumper that will break on typed
> references:
> 
> the only way to detect references is by injecting cookies in arrays, e.g.:
> $a = (array) $someObjectOrArray;
> $cookie = new stdClass();
> $b = $a;
> $b[$k] = $cookie;
> if ($a[$k] === $cookie) {
>   // Here we have a reference
> }
> 
> I'd need to wrap the assignation in a try/catch now:
> try {
>     $b[$k] = $cookie;
> } catch (TypeError $e) {
>   // Here we have a typed reference that doesn't accept stdclass }
> 
> So far so good I suppose. I just wanted to raise the point if it matters at 
> all.
> 
> Thank you,
> Nicolas

We haven't implemented that (yet?), but I considered something like a 
ReflectionReference class, which will give you the referencing properties via 
ReflectionProperty instances.
The implementation easily allows for that as it tracks the referencing 
properties for calculating the allowed types.

I didn't consider it essential for the initial implementation in 7.3 and thus 
hadn't written it on the TODO list for that RFC.
But if you think it's important (it has real world needs), then we may consider 
extending the RFC to include that.

Bob

Reply via email to