Skip to content
Permalink
Browse files

feature #19630 [VarDumper] Enhance dumping __PHP_Incomplete_Class obj…

…ects (nicolas-grekas)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[VarDumper] Enhance dumping __PHP_Incomplete_Class objects

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Before:
```
__PHP_Incomplete_Class {
  +"__PHP_Incomplete_Class_Name": "Foo\Buzz"
}
```

after:
```
__PHP_Incomplete_Class(Foo\Buzz) {}
```

The new output is less confusing: no dynamic property exists on incomplete class objects, yet the `+` prefix suggests that.

Commits
-------

ee20d15 [VarDumper] Enhance dumping __PHP_Incomplete_Class objects
  • Loading branch information...
fabpot committed Aug 16, 2016
2 parents 5cc9ed2 + ee20d15 commit f56ba630db415d8854ec32d674ba0ae4ef99eee2
@@ -11,6 +11,8 @@
namespace Symfony\Component\VarDumper\Caster;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
* Helper for filtering out properties in casters.
*
@@ -50,6 +52,9 @@ public static function castObject($obj, \ReflectionClass $reflector)
} else {
$a = (array) $obj;
}
if ($obj instanceof \__PHP_Incomplete_Class) {
return $a;
}
if ($a) {
$p = array_keys($a);
@@ -119,4 +124,12 @@ public static function filter(array $a, $filter, array $listedProperties = array
return $a;
}
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, $isNested)
{
$stub->class .= '('.$a['__PHP_Incomplete_Class_Name'].')';
unset($a['__PHP_Incomplete_Class_Name']);
return $a;
}
}
@@ -22,6 +22,8 @@
abstract class AbstractCloner implements ClonerInterface
{
public static $defaultCasters = array(
'__PHP_Incomplete_Class' => 'Symfony\Component\VarDumper\Caster\Caster::castPhpIncompleteClass',
'Symfony\Component\VarDumper\Caster\CutStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castStub',
'Symfony\Component\VarDumper\Caster\CutArrayStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castCutArray',
'Symfony\Component\VarDumper\Caster\ConstStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castStub',
@@ -461,6 +461,21 @@ public function testBuggyRefs()
);
}
public function testIncompleteClass()
{
$unserializeCallbackHandler = ini_set('unserialize_callback_func', null);
$var = unserialize('O:8:"Foo\Buzz":0:{}');
ini_set('unserialize_callback_func', $unserializeCallbackHandler);
$this->assertDumpMatchesFormat(
<<<EOTXT
__PHP_Incomplete_Class(Foo\Buzz) {}
EOTXT
,
$var
);
}
private function getSpecialVars()
{
foreach (array_keys($GLOBALS) as $var) {

0 comments on commit f56ba63

Please sign in to comment.
You can’t perform that action at this time.