bug #13785 [VarDumper] Workaround stringy numeric keys (nicolas-grekas)
This PR was merged into the 2.6 branch.
Discussion
----------
[VarDumper] Workaround stringy numeric keys
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #13784
| License | MIT
| Doc PR | -
Commits
-------
46bea3a
[VarDumper] Workaround stringy numeric keys
This commit is contained in:
commit
70ba475156
@ -199,15 +199,17 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
}
|
||||
|
||||
if ($classInfo[1]) {
|
||||
$a = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
|
||||
$p = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
|
||||
} else {
|
||||
$a = (array) $obj;
|
||||
$p = (array) $obj;
|
||||
}
|
||||
|
||||
foreach ($a as $k => $p) {
|
||||
$a = array();
|
||||
foreach ($p as $k => $p) {
|
||||
if (!isset($k[0]) || ("\0" !== $k[0] && !$classInfo[2]->hasProperty($k))) {
|
||||
unset($a[$k]);
|
||||
$a["\0+\0".$k] = $p;
|
||||
} else {
|
||||
$a[$k] = $p;
|
||||
}
|
||||
}
|
||||
|
||||
|
94
src/Symfony/Component/VarDumper/Tests/VarClonerTest.php
Normal file
94
src/Symfony/Component/VarDumper/Tests/VarClonerTest.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class VarClonerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testClone()
|
||||
{
|
||||
$json = json_decode('{"1":{"var":"val"},"2":{"var":"val"}}');
|
||||
|
||||
$cloner = new VarCloner();
|
||||
$clone = $cloner->cloneVar($json);
|
||||
|
||||
$expected = <<<EOTXT
|
||||
Symfony\Component\VarDumper\Cloner\Data Object
|
||||
(
|
||||
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||
(
|
||||
[type] => object
|
||||
[class] => stdClass
|
||||
[value] =>
|
||||
[cut] => 0
|
||||
[handle] => %d
|
||||
[refCount] => 0
|
||||
[position] => 1
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[\000+\0001] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||
(
|
||||
[type] => object
|
||||
[class] => stdClass
|
||||
[value] =>
|
||||
[cut] => 0
|
||||
[handle] => %d
|
||||
[refCount] => 0
|
||||
[position] => 2
|
||||
)
|
||||
|
||||
[\000+\0002] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||
(
|
||||
[type] => object
|
||||
[class] => stdClass
|
||||
[value] =>
|
||||
[cut] => 0
|
||||
[handle] => %d
|
||||
[refCount] => 0
|
||||
[position] => 3
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[\000+\000var] => val
|
||||
)
|
||||
|
||||
[3] => Array
|
||||
(
|
||||
[\000+\000var] => val
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
|
||||
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
||||
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
||||
)
|
||||
|
||||
EOTXT;
|
||||
$this->assertStringMatchesFormat($expected, print_r($clone, true));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user