8000 [VarDumper] Fix PHP7 type-hints compat · symfony/symfony@edd5633 · GitHub
[go: up one dir, main page]

Skip to content

Commit edd5633

Browse files
[VarDumper] Fix PHP7 type-hints compat
1 parent 1bed177 commit edd5633

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
167167
));
168168

169169
try {
170-
if ($c->isArray()) {
170+
if (method_exists($c, 'hasType')) {
171+
if ($c->hasType()) {
172+
$a[$prefix.'typeHint'] = $c->getType()->__toString();
173+
}
174+
} elseif ($c->isArray()) {
171175
$a[$prefix.'typeHint'] = 'array';
172176
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
173177
$a[$prefix.'typeHint'] = 'callable';

src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,41 @@ public function testReflectionParameter()
7878
);
7979
}
8080

81+
/**
82+
* @requires PHP 7.0
83+
*/
84+
public function testReflectionParameterScalar()
85+
{
86+
$f = eval('return function (int $a) {};');
87+
$var = new \ReflectionParameter($f, 0);
88+
89+
$this->assertDumpMatchesFormat(
90+
<<<'EOTXT'
91+
ReflectionParameter {
92+
+name: "a"
93+
position: 0
94+
typeHint: "int"
95+
}
96+
EOTXT
97+
, $var
98+
);
99+
}
100+
81101
/**
82102
* @requires PHP 7.0
83103
*/
84104
public function testReturnType()
85105
{
86106
$f = eval('return function ():int {};');
107+
$line = __LINE__ - 1;
87108

88109
$this->assertDumpMatchesFormat(
89-
<<<'EOTXT'
110+
<<<EOTXT
90111
Closure {
91112
returnType: "int"
92113
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
93114
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
94-
file: "%sReflectionCasterTest.php(86) : eval()'d code"
115+
file: "%sReflectionCasterTest.php($line) : eval()'d code"
95116
line: "1 to 1"
96117
}
97118
EOTXT

0 commit comments

Comments
 (0)
0