8000 [VarDumper] Workaround stringy numeric keys · symfony/symfony@46bea3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 46bea3a

Browse files
[VarDumper] Workaround stringy numeric keys
1 parent 9f5a2ca commit 46bea3a

File tree

2 files changed

+100
-4
lines changed

2 files changed

+100
-4
lines changed

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,17 @@ protected function castObject(Stub $stub, $isNested)
199199
}
200200

201201
if ($classInfo[1]) {
202-
$a = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
202+
$p = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
203203
} else {
204-
$a = (array) $obj;
204+
$p = (array) $obj;
205205
}
206206

207-
foreach ($a as $k => $p) {
207+
$a = array();
208+
foreach ($p as $k => $p) {
208209
if (!isset($k[0]) || ("\0" !== $k[0] && !$classInfo[2]->hasProperty($k))) {
209-
unset($a[$k]);
210210
$a["\0+\0".$k] = $p;
211+
} else {
212+
$a[$k] = $p;
211213
}
212214
}
213215

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Tests;
13+
14+
use Symfony\Component\VarDumper\Cloner\VarCloner;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class VarClonerTest extends \PHPUnit_Framework_TestCase
20+
{
21+
public function testClone()
22+
{
23+
$json = json_decode('{"1":{"var":"val"},"2":{"var":"val"}}');
24+
25+
$cloner = new VarCloner();
26+
$clone = $cloner->cloneVar($json);
27+
28+
$expected = <<<EOTXT
29+
Symfony\Component\VarDumper\Cloner\Data Object
30+
(
31+
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
32+
(
33+
[0] => Array
34+
(
35+
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
36+
(
37+
[type] => object
38+
[class] => stdClass
39+
[value] =>
40+
[cut] => 0
41+
[handle] => %d
42+
[refCount] => 0
43+
[position] => 1
44+
)
45+
46+
)
47+
48+
[1] => Array
49+
(
50+
[\000+\0001] => Symfony\Component\VarDumper\Cloner\Stub Object
51+
(
52+
[type] => object
53+
[class] => stdClass
54+
[value] =>
55+
[cut] => 0
56+
[handle] => %d
57+
[refCount] => 0
58+
[position] => 2
59+
)
60+
61+
[\000+\0002] => Symfony\Component\VarDumper\Cloner\Stub Object
62+
(
63+
[type] => object
64+
[class] => stdClass
65+
[value] =>
66+
[cut] => 0
67+
[handle] => %d
68+
[refCount] => 0
69+
[position] => 3
70+
)
71+
72+
)
73+
74+
[2] => Array
75+
(
76+
[\000+\000var] => val
77+
)
78+
79+
[3] => Array
80+
(
81+
[\000+\000var] => val
82+
)
83+
84+
)
85+
86+
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
87+
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
88+
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
89+
)
90+
91+
EOTXT;
92+
$this->assertStringMatchesFormat($expected, print_r($clone, true));
93+
}
94+
}

0 commit comments

Comments
 (0)
0