> 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. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php