diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index df677002be4b..6345ad7fde2b 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -54,6 +54,8 @@ public static function castObject($obj, \ReflectionClass $reflector) foreach ($p as $i => $k) { if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) { $p[$i] = self::PREFIX_DYNAMIC.$k; + } elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) { + $p[$i] = "\0anonymous-".$reflector->name.strrchr($k, "\0"); } } $a = array_combine($p, $a); diff --git a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php index 48c5fd6f3672..04cf7b05526c 100644 --- a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php @@ -114,6 +114,9 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra 'this' => 'getClosureThis', )); + if (isset($a[$prefix.'returnType'])) { + $a[$prefix.'returnType'] = (string) $a[$prefix.'returnType']; + } if (isset($a[$prefix.'this'])) { $a[$prefix.'this'] = new CutStub($a[$prefix.'this']); } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index bdc286343709..9a29dd5e209a 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -208,9 +208,12 @@ protected function castObject(Stub $stub, $isNested) $obj = $stub->value; $class = $stub->class; + if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) { + $class = get_parent_class($class); + $stub->class = 'anonymous-'.$class; + } if (isset($this->classInfo[$class])) { $classInfo = $this->classInfo[$class]; - $stub->class = $classInfo[0]; } else { $classInfo = array( $class, diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php index d8ad81a87785..1f30f2aa3486 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php @@ -12,11 +12,12 @@ namespace Symfony\Component\VarDumper\Tests\Caster; use Symfony\Component\VarDumper\Caster\Caster; +use Symfony\Component\VarDumper\Test\VarDumperTestCase; /** * @author Nicolas Grekas */ -class CasterTest extends \PHPUnit_Framework_TestCase +class CasterTest extends VarDumperTestCase { private $referenceArray = array( 'null' => null, @@ -28,7 +29,9 @@ class CasterTest extends \PHPUnit_Framework_TestCase "\0Foo\0private" => 'priv', ); - /** @dataProvider provideFilter */ + /** + * @dataProvider provideFilter + */ public function testFilter($filter, $expectedDiff, $listedProperties = null) { if (null === $listedProperties) { @@ -144,4 +147,21 @@ public function provideFilter() ), ); } + + /** + * @requires PHP 7.0 + */ + public function testAnonymousClass() + { + $c = eval('return new class extends stdClass { private $foo = "foo"; };'); + + $this->assertDumpMatchesFormat( + <<<'EOTXT' +anonymous-stdClass { + -foo: "foo" +} +EOTXT + , $c + ); + } } diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 0fcc7e26bb36..edb6b1f4aadc 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -60,4 +60,25 @@ public function testReflectionCaster() , $var ); } + + /** + * @requires PHP 7.0 + */ + public function testReturnType() + { + $f = eval('return function ():int {};'); + + $this->assertDumpMatchesFormat( + <<<'EOTXT' +Closure { + returnType: "int" + class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest" + this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …} + file: "%sReflectionCasterTest.php(69) : eval()'d code" + line: "1 to 1" +} +EOTXT + , $f + ); + } }