bug #16480 [VarDumper] Fix PHP7 type-hints compat (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[VarDumper] Fix PHP7 type-hints compat
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
edd5633
[VarDumper] Fix PHP7 type-hints compat
This commit is contained in:
commit
f75f44b7c5
@ -167,7 +167,11 @@ class ReflectionCaster
|
|||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($c->isArray()) {
|
if (method_exists($c, 'hasType')) {
|
||||||
|
if ($c->hasType()) {
|
||||||
|
$a[$prefix.'typeHint'] = $c->getType()->__toString();
|
||||||
|
}
|
||||||
|
} elseif ($c->isArray()) {
|
||||||
$a[$prefix.'typeHint'] = 'array';
|
$a[$prefix.'typeHint'] = 'array';
|
||||||
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
|
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
|
||||||
$a[$prefix.'typeHint'] = 'callable';
|
$a[$prefix.'typeHint'] = 'callable';
|
||||||
|
@ -81,17 +81,38 @@ EOTXT
|
|||||||
/**
|
/**
|
||||||
* @requires PHP 7.0
|
* @requires PHP 7.0
|
||||||
*/
|
*/
|
||||||
public function testReturnType()
|
public function testReflectionParameterScalar()
|
||||||
{
|
{
|
||||||
$f = eval('return function ():int {};');
|
$f = eval('return function (int $a) {};');
|
||||||
|
$var = new \ReflectionParameter($f, 0);
|
||||||
|
|
||||||
$this->assertDumpMatchesFormat(
|
$this->assertDumpMatchesFormat(
|
||||||
<<<'EOTXT'
|
<<<'EOTXT'
|
||||||
|
ReflectionParameter {
|
||||||
|
+name: "a"
|
||||||
|
position: 0
|
||||||
|
typeHint: "int"
|
||||||
|
}
|
||||||
|
EOTXT
|
||||||
|
, $var
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 7.0
|
||||||
|
*/
|
||||||
|
public function testReturnType()
|
||||||
|
{
|
||||||
|
$f = eval('return function ():int {};');
|
||||||
|
$line = __LINE__ - 1;
|
||||||
|
|
||||||
|
$this->assertDumpMatchesFormat(
|
||||||
|
<<<EOTXT
|
||||||
Closure {
|
Closure {
|
||||||
returnType: "int"
|
returnType: "int"
|
||||||
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
|
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
|
||||||
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
|
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
|
||||||
file: "%sReflectionCasterTest.php(86) : eval()'d code"
|
file: "%sReflectionCasterTest.php($line) : eval()'d code"
|
||||||
line: "1 to 1"
|
line: "1 to 1"
|
||||||
}
|
}
|
||||||
EOTXT
|
EOTXT
|
||||||
|
Reference in New Issue
Block a user