fix reflection parameter problem where type and type hint were made to collide. Separated the two...

ReflectoinParamenter was fetching both type and type hint from the same field. That created an incompatible change with existing code and broke the mocking framework. Separated the type and type hint field to contain the possible different values.
Esse commit está contido em:
Dario Russi
2013-04-24 16:00:00 -07:00
commit de Sara Golemon
commit 6e510c2081
6 arquivos alterados com 42 adições e 10 exclusões
+6 -2
Ver Arquivo
@@ -83,6 +83,7 @@ static StaticString s___invoke("__invoke");
static StaticString s_closure_in_braces("{closure}");
static StaticString s_closureobj("closureobj");
static StaticString s_return_type("return_type");
static StaticString s_type_hint("type_hint");
static const VM::Class* get_cls(CVarRef class_or_object) {
VM::Class* cls = NULL;
@@ -348,9 +349,12 @@ static void set_function_info(Array &ret, const VM::Func* func) {
param.set(s_index, VarNR((int)i));
VarNR name(func->localNames()[i]);
param.set(s_name, name);
const StringData* type = fpi.userType() ?
fpi.userType() : empty_string.get();
const StringData* type = fpi.typeConstraint().exists() ?
fpi.typeConstraint().typeName() : empty_string.get();
param.set(s_type, VarNR(type));
const StringData* typeHint = fpi.userType() ?
fpi.userType() : empty_string.get();
param.set(s_type_hint, VarNR(typeHint));
param.set(s_function, VarNR(func->name()));
if (func->preClass()) {
param.set(s_class, VarNR(func->cls() ? func->cls()->name() :
+2 -2
Ver Arquivo
@@ -162,8 +162,8 @@ class ReflectionParameter implements Reflector {
}
public function getTypehintText() {
if (isset($this->info['type'])) {
return $this->info['type'];
if (isset($this->info['type_hint'])) {
return $this->info['type_hint'];
}
return '';
}
+12 -4
Ver Arquivo
@@ -27,13 +27,15 @@ array(4) {
[0]=>
object(ReflectionParameter)#5 (1) {
["info"]=>
array(6) {
array(7) {
["index"]=>
int(0)
["name"]=>
string(1) "a"
["type"]=>
string(0) ""
["type_hint"]=>
string(0) ""
["function"]=>
string(1) "f"
["nullable"]=>
@@ -46,13 +48,15 @@ array(4) {
[1]=>
object(ReflectionParameter)#6 (1) {
["info"]=>
array(7) {
array(8) {
["index"]=>
int(1)
["name"]=>
string(1) "b"
["type"]=>
string(0) ""
["type_hint"]=>
string(0) ""
["function"]=>
string(1) "f"
["nullable"]=>
@@ -67,13 +71,15 @@ array(4) {
[2]=>
object(ReflectionParameter)#7 (1) {
["info"]=>
array(8) {
array(9) {
["index"]=>
int(2)
["name"]=>
string(1) "c"
["type"]=>
string(0) ""
["type_hint"]=>
string(0) ""
["function"]=>
string(1) "f"
["nullable"]=>
@@ -90,13 +96,15 @@ array(4) {
[3]=>
object(ReflectionParameter)#8 (1) {
["info"]=>
array(8) {
array(9) {
["index"]=>
int(3)
["name"]=>
string(1) "d"
["type"]=>
string(0) ""
["type_hint"]=>
string(0) ""
["function"]=>
string(1) "f"
["nullable"]=>
+3 -1
Ver Arquivo
@@ -248,13 +248,15 @@ array(6) {
}
object(ReflectionParameter)#9 (1) {
["info"]=>
array(6) {
array(7) {
["index"]=>
int(0)
["name"]=>
string(1) "c"
["type"]=>
string(7) "MyClass"
["type_hint"]=>
string(7) "MyClass"
["function"]=>
string(1) "f"
["class"]=>
+11 -1
Ver Arquivo
@@ -137,4 +137,14 @@ class TC {
}
$rc = new ReflectionClass('TC');
printClass($rc);
function ff(Vector<int> $i, ?string $s, @C $c, array $a) {}
$rf = new ReflectionFunction('ff');
$rps = $rf->getParameters();
foreach ($rps as $rp) {
var_dump($rp->getTypehintText());
if ($rp->getClass() != null) {
var_dump($rp->getClass()->getName());
} else {
var_dump("");
}
}
@@ -63,3 +63,11 @@ string(9) ":xhp:html"
string(26) "@array<C, ?Vector<string>>"
string(41) "(function (@int, (double, string)): void)"
string(38) "array<Map<CT<int, string>, :xhp:html>>"
string(11) "Vector<int>"
string(6) "Vector"
string(7) "?string"
string(0) ""
string(2) "@C"
string(0) ""
string(5) "array"
string(0) ""