diff --git a/hphp/runtime/ext/reflection/ext_reflection.cpp b/hphp/runtime/ext/reflection/ext_reflection.cpp index bf90792f81182..1ab37e01f45b2 100644 --- a/hphp/runtime/ext/reflection/ext_reflection.cpp +++ b/hphp/runtime/ext/reflection/ext_reflection.cpp @@ -1922,13 +1922,15 @@ const StaticString s_ReflectionTypeAliasHandle("ReflectionTypeAliasHandle"); // helper for __construct: // caller throws exception when return value is false -static bool HHVM_METHOD(ReflectionTypeAlias, __init, const String& name) { +static String HHVM_METHOD(ReflectionTypeAlias, __init, const String& name) { auto const typeAliasReq = Unit::loadTypeAlias(name.get()); - if (!typeAliasReq) return false; + if (!typeAliasReq) { + return empty_string(); + } ReflectionTypeAliasHandle::Get(this_)->setTypeAliasReq(typeAliasReq); - return true; + return String::attach(const_cast(typeAliasReq->name.get())); } static Array HHVM_METHOD(ReflectionTypeAlias, getTypeStructure) { diff --git a/hphp/runtime/ext/reflection/ext_reflection_hni.php b/hphp/runtime/ext/reflection/ext_reflection_hni.php index 6915a857d97fd..3241291a04a51 100644 --- a/hphp/runtime/ext/reflection/ext_reflection_hni.php +++ b/hphp/runtime/ext/reflection/ext_reflection_hni.php @@ -1142,11 +1142,11 @@ public function __construct(mixed $name_or_obj) { } else { $classname = $name_or_obj; } - if (!$this->__init($classname)) { + $name = $this->__init($classname); + if (!$name) { throw new ReflectionException("Class $classname does not exist"); } - - $this->name = $this->getName(); + $this->name = $name; } <<__Native>> @@ -2400,16 +2400,17 @@ class ReflectionTypeAlias implements Reflector { * @name string Name of the type alias. */ final public function __construct(string $name) { - if (!$this->__init($name)) { + $n = $this->__init($name); + if (!$n) { throw new ReflectionException( "type alias {$name} does not exist"); } - $this->name = $name; + $this->name = $n; } // helper for ctor <<__Native>> - private function __init(string $name): bool; + private function __init(string $name): string; /** * Get the TypeStructure that contains the full type information of diff --git a/hphp/test/slow/reflection/ReflectionTypeAlias7.php b/hphp/test/slow/reflection/ReflectionTypeAlias7.php new file mode 100644 index 0000000000000..c18e0974c5aad --- /dev/null +++ b/hphp/test/slow/reflection/ReflectionTypeAlias7.php @@ -0,0 +1,6 @@ +getName(), "\n"; diff --git a/hphp/test/slow/reflection/ReflectionTypeAlias7.php.expect b/hphp/test/slow/reflection/ReflectionTypeAlias7.php.expect new file mode 100644 index 0000000000000..3a2ef5da67c59 --- /dev/null +++ b/hphp/test/slow/reflection/ReflectionTypeAlias7.php.expect @@ -0,0 +1 @@ +MyType