RE: [PHP-DEV] [RFC] Typed Properties
| From: | Bob Weinand | Date: | Thu, 21 Jun 2018 17:22:03 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] Typed Properties | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102359@lists.php.net to get a copy of this message | ||
From: nicolas.grekas@gmail.com <nicolas.grekas@gmail.com> On Behalf Of Nicolas Grekas
Sent: Thursday, June 21, 2018 18:51
To: Bob Weinand <bobwei9@hotmail.com>
Cc: Nikita Popov <nikita.ppv@gmail.com>; PHP internals <internals@lists.php.net>
Subject: Re: [PHP-DEV] [RFC] Typed Properties
something like a ReflectionReference class, which will give you the referencing properties via
ReflectionProperty instances
I may not have the object when walking on data structures, but only the reference (in an array.)
It could work this way I suppose:
ReflectionReference::fromArray(array $array, string $key):
?ReflectionReference,
returning null when $array[$key] is not a reference, and the instance
otherwise.
WDYT?
I imagined a ReflectionReference::__construct(&$value), with methods getRefcount() : int and
getReferencingProperties() : ReflectionProperty[]
To check whether it’s a reference at all, you’d use if ((new
ReflectionReference($array[$key]))->getRefcount() > 2) { /* is ref */ } else { /* not a ref */
}, for computing the allowed types you’d intersect the types of the ReflectionProperties returned
by getReferencingProperties().
Bob