From edd5633374857e31d57c391bea88b8d4d343d55c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 6 Nov 2015 09:22:03 +0100 Subject: [PATCH] [VarDumper] Fix PHP7 type-hints compat --- .../VarDumper/Caster/ReflectionCaster.php | 6 ++++- .../Tests/Caster/ReflectionCasterTest.php | 27 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php index a302835f08..cacd2113d7 100644 --- a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php @@ -167,7 +167,11 @@ class ReflectionCaster )); 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'; } elseif (method_exists($c, 'isCallable') && $c->isCallable()) { $a[$prefix.'typeHint'] = 'callable'; diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 4120d341da..5c306a6710 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -81,17 +81,38 @@ EOTXT /** * @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( <<<'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( + <<