Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/Caster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 22 additions & 2 deletions src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <p@tchwork.com>
*/
class CasterTest extends \PHPUnit_Framework_TestCase
class CasterTest extends VarDumperTestCase
{
private $referenceArray = array(
'null' => null,
Expand All @@ -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) {
Expand Down Expand Up @@ -144,4 +147,21 @@ public function provideFilter()
),
);
}

/**
* @requires PHP 7.0
*/
public function testAnonymousClass()
{
$c = eval('return new class extends stdClass { private $foo = "foo"; };');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about an anonymous class not extending any parent class ? Is it valid ?


$this->assertDumpMatchesFormat(
<<<'EOTXT'
anonymous-stdClass {
-foo: "foo"
}
EOTXT
, $c
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}