Re: [RFC][Vote] ReflectionType Improvements
| From: | Levi Morrison | Date: | Tue, 05 Jul 2016 21:06:12 +0000 |
| Subject: | Re: [RFC][Vote] ReflectionType Improvements | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94394@lists.php.net to get a copy of this message | ||
> Or if the aim is to simplify the reflection usage, why require the if
> statement at all:
>
> try {
> $r = $type->getReflectionClass();
> } catch ( ReflectionException $e ) {
> // type is builtin or refers to an undefined class
> }
I don't think this is actually simpler if you expand the comment to
handle both cases:
try {
$r = $type->getReflectionClass();
handle_class($type);
} catch (ReflectionException $e) {
if ($type->isBuiltin()) {
handle_builtin();
} else {
handle_undefined($type);
}
}
Compare that to using only if-else for control flow:
if ($type->isBuiltin()) {
handle_builtin();
} else if ($type instanceof ReflectionClassType) {
handle_class($type);
} else {
handle_undefined($type);
}
I'd much prefer the latter.
Another option is adding a method
hasClass() that would return
true if a getClass() call would be considered valid and false
otherwise. To me this doesn't seem as good as subtypes but consider it
better than forcing a caller to handle an exception in a situation
that I don't consider exceptional.
It would have been great if people actually contributed to the
discussion before voting phase, but such is life.