Skip to content

Commit

Permalink
Fix ReflectionTypeAlias::getName
Browse files Browse the repository at this point in the history
Summary:
It should return the properly cased name, not the name that was passed
in.

Reviewed By: alexeyt

Differential Revision: D5742110

fbshipit-source-id: 29eb8fcc3adc89ea9ff7eb7736f09ed46348abef
  • Loading branch information
Mark Williams authored and hhvm-bot committed Aug 31, 2017
1 parent 6fb1754 commit a677870
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
8 changes: 5 additions & 3 deletions hphp/runtime/ext/reflection/ext_reflection.cpp
Expand Up @@ -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<StringData*>(typeAliasReq->name.get()));
}

static Array HHVM_METHOD(ReflectionTypeAlias, getTypeStructure) {
Expand Down
13 changes: 7 additions & 6 deletions hphp/runtime/ext/reflection/ext_reflection_hni.php
Expand Up @@ -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>>
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions hphp/test/slow/reflection/ReflectionTypeAlias7.php
@@ -0,0 +1,6 @@
<?hh

type MyType = void;

$x = new ReflectionTypeAlias('mytype');
echo $x->getName(), "\n";
1 change: 1 addition & 0 deletions hphp/test/slow/reflection/ReflectionTypeAlias7.php.expect
@@ -0,0 +1 @@
MyType

0 comments on commit a677870

Please sign in to comment.