Skip to content

Commit 66d64f3

Browse files
Merge branch '3.4' into 4.4
* 3.4: Run PHP 8 as 7.4.99 [VarDumper] fix PHP 8 support Add php 8 to travis. [Cache] Accessing undefined constants raises an Error in php8
2 parents 77d81a0 + 7a947d1 commit 66d64f3

File tree

9 files changed

+34
-30
lines changed

9 files changed

+34
-30
lines changed

Caster/Caster.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Caster
4545
*
4646
* @return array The array-cast of the object, with prefixed dynamic properties
4747
*/
48-
public static function castObject($obj, string $class, bool $hasDebugInfo = false): array
48+
public static function castObject($obj, string $class, bool $hasDebugInfo = false, string $debugClass = null): array
4949
{
5050
if ($hasDebugInfo) {
5151
try {
@@ -64,6 +64,7 @@ public static function castObject($obj, string $class, bool $hasDebugInfo = fals
6464

6565
if ($a) {
6666
static $publicProperties = [];
67+
$debugClass = $debugClass ?? get_debug_type($obj);
6768

6869
$i = 0;
6970
$prefixedKeys = [];
@@ -77,8 +78,8 @@ public static function castObject($obj, string $class, bool $hasDebugInfo = fals
7778
if (!isset($publicProperties[$class][$k])) {
7879
$prefixedKeys[$i] = self::PREFIX_DYNAMIC.$k;
7980
}
80-
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
81-
$prefixedKeys[$i] = "\0".get_parent_class($class).'@anonymous'.strrchr($k, "\0");
81+
} elseif ($debugClass !== $class && 1 === strpos($k, $class)) {
82+
$prefixedKeys[$i] = "\0".$debugClass.strrchr($k, "\0");
8283
}
8384
++$i;
8485
}
@@ -94,6 +95,9 @@ public static function castObject($obj, string $class, bool $hasDebugInfo = fals
9495
if ($hasDebugInfo && \is_array($debugInfo)) {
9596
foreach ($debugInfo as $k => $v) {
9697
if (!isset($k[0]) || "\0" !== $k[0]) {
98+
if (\array_key_exists(self::PREFIX_DYNAMIC.$k, $a)) {
99+
continue;
100+
}
97101
$k = self::PREFIX_VIRTUAL.$k;
98102
}
99103

Caster/SplCaster.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,6 @@ public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $
162162
return $a;
163163
}
164164

165-
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested)
166-
{
167-
$a += [
168-
Caster::PREFIX_VIRTUAL.'storage' => $c->toArray(),
169-
];
170-
171-
return $a;
172-
}
173-
174165
public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested)
175166
{
176167
$storage = [];
@@ -209,22 +200,23 @@ public static function castWeakReference(\WeakReference $c, array $a, Stub $stub
209200
private static function castSplArray($c, array $a, Stub $stub, bool $isNested): array
210201
{
211202
$prefix = Caster::PREFIX_VIRTUAL;
212-
$class = $stub->class;
213203
$flags = $c->getFlags();
214204

215205
if (!($flags & \ArrayObject::STD_PROP_LIST)) {
216206
$c->setFlags(\ArrayObject::STD_PROP_LIST);
217-
$a = Caster::castObject($c, $class);
207+
$a = Caster::castObject($c, \get_class($c), method_exists($c, '__debugInfo'), $stub->class);
218208
$c->setFlags($flags);
219209
}
210+
if (\PHP_VERSION_ID < 70400) {
211+
$a[$prefix.'storage'] = $c->getArrayCopy();
212+
}
220213
$a += [
221214
$prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
222215
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
223216
];
224217
if ($c instanceof \ArrayObject) {
225218
$a[$prefix.'iteratorClass'] = new ClassStub($c->getIteratorClass());
226219
}
227-
$a[$prefix.'storage'] = $c->getArrayCopy();
228220

229221
return $a;
230222
}

Cloner/AbstractCloner.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ abstract class AbstractCloner implements ClonerInterface
114114
'SplDoublyLinkedList' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'],
115115
'SplFileInfo' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'],
116116
'SplFileObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'],
117-
'SplFixedArray' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFixedArray'],
118117
'SplHeap' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
119118
'SplObjectStorage' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'],
120119
'SplPriorityQueue' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
@@ -291,8 +290,8 @@ protected function castObject(Stub $stub, $isNested)
291290
$obj = $stub->value;
292291
$class = $stub->class;
293292

294-
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
295-
$stub->class = get_parent_class($class).'@anonymous';
293+
if (\PHP_VERSION_ID < 80000 ? "\0" === ($class[15] ?? null) : false !== strpos($class, "@anonymous\0")) {
294+
$stub->class = get_debug_type($obj);
296295
}
297296
if (isset($this->classInfo[$class])) {
298297
list($i, $parents, $hasDebugInfo, $fileInfo) = $this->classInfo[$class];
@@ -321,7 +320,7 @@ protected function castObject(Stub $stub, $isNested)
321320
}
322321

323322
$stub->attr += $fileInfo;
324-
$a = Caster::castObject($obj, $class, $hasDebugInfo);
323+
$a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class);
325324

326325
try {
327326
while ($i--) {

Tests/Caster/CasterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testAnonymousClass()
168168

169169
$this->assertDumpMatchesFormat(
170170
<<<'EOTXT'
171-
@anonymous {
171+
class@anonymous {
172172
-foo: "foo"
173173
}
174174
EOTXT

Tests/Caster/PdoCasterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function testCastPdo()
3030
{
3131
$pdo = new \PDO('sqlite::memory:');
3232
$pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, ['PDOStatement', [$pdo]]);
33+
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
3334

3435
$cast = PdoCaster::castPdo($pdo, [], new Stub(), false);
3536

@@ -45,7 +46,7 @@ public function testCastPdo()
4546
"\x00~\x00inTransaction" => false
4647
"\x00~\x00attributes" => array:9 [
4748
"CASE" => NATURAL
48-
"ERRMODE" => SILENT
49+
"ERRMODE" => EXCEPTION
4950
"PERSISTENT" => false
5051
"DRIVER_NAME" => "sqlite"
5152
"ORACLE_NULLS" => NATURAL

Tests/Caster/ReflectionCasterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function testReflectionCaster()
4949
%A]
5050
methods: array:%d [
5151
%A
52-
"export" => ReflectionMethod {
53-
+name: "export"
52+
"__construct" => ReflectionMethod {
53+
+name: "__construct"
5454
+class: "ReflectionClass"
5555
%A parameters: {
5656
$%s: ReflectionParameter {

Tests/Caster/SplCasterTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,17 @@ public function testCastArrayObject()
172172
$expected = <<<EOTXT
173173
ArrayObject {
174174
+"foo": 234
175+
-storage: array:1 [
176+
0 => 123
177+
]
175178
flag::STD_PROP_LIST: false
176179
flag::ARRAY_AS_PROPS: false
177180
iteratorClass: "ArrayIterator"
178-
storage: array:1 [
179-
0 => 123
180-
]
181181
}
182182
EOTXT;
183+
if (\PHP_VERSION_ID < 70400) {
184+
$expected = str_replace('-storage:', 'storage:', $expected);
185+
}
183186
$this->assertDumpEquals($expected, $var);
184187
}
185188

@@ -190,13 +193,16 @@ public function testArrayIterator()
190193
$expected = <<<EOTXT
191194
Symfony\Component\VarDumper\Tests\Caster\MyArrayIterator {
192195
-foo: 123
193-
flag::STD_PROP_LIST: false
194-
flag::ARRAY_AS_PROPS: false
195-
storage: array:1 [
196+
-storage: array:1 [
196197
0 => 234
197198
]
199+
flag::STD_PROP_LIST: false
200+
flag::ARRAY_AS_PROPS: false
198201
}
199202
EOTXT;
203+
if (\PHP_VERSION_ID < 70400) {
204+
$expected = str_replace('-storage:', 'storage:', $expected);
205+
}
200206
$this->assertDumpEquals($expected, $var);
201207
}
202208

Tests/Dumper/CliDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public function provideDumpWithCommaFlagTests()
199199

200200
/**
201201
* @requires extension xml
202+
* @requires PHP < 8.0
202203
*/
203204
public function testXmlResource()
204205
{

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"require": {
1919
"php": ">=7.1.3",
2020
"symfony/polyfill-mbstring": "~1.0",
21-
"symfony/polyfill-php72": "~1.5"
21+
"symfony/polyfill-php72": "~1.5",
22+
"symfony/polyfill-php80": "^1.15"
2223
},
2324
"require-dev": {
2425
"ext-iconv": "*",

0 commit comments

Comments
 (0)