Skip to content

Commit 25095a0

Browse files
Merge branch '4.4' into 5.0
* 4.4: (27 commits) [Serializer] minor cleanup fix merge Run PHP 8 as 7.4.99 Remove calls to deprecated ReflectionParameter::getClass(). [VarDumper] fix PHP 8 support Add php 8 to travis. [Cache] Accessing undefined constants raises an Error in php8 [Cache] allow DBAL v3 Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. Made method signatures compatible with their corresponding traits. [ErrorHandler] Apply php8 fixes from Debug component. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [BrowserKit] Raw body with custom Content-Type header [PropertyAccess] Parse php 8 TypeErrors correctly. [Intl] Fix call to ReflectionProperty::getValue() for static properties. [HttpKernel] Prevent calling method_exists() with non-string values. Fix wrong roles comparison ...
2 parents 2d5f245 + 66d64f3 commit 25095a0

File tree

10 files changed

+38
-30
lines changed

10 files changed

+38
-30
lines changed

Caster/Caster.php

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

6464
if ($a) {
6565
static $publicProperties = [];
66+
$debugClass = $debugClass ?? get_debug_type($obj);
6667

6768
$i = 0;
6869
$prefixedKeys = [];
@@ -76,8 +77,8 @@ public static function castObject(object $obj, string $class, bool $hasDebugInfo
7677
if (!isset($publicProperties[$class][$k])) {
7778
$prefixedKeys[$i] = self::PREFIX_DYNAMIC.$k;
7879
}
79-
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
80-
$prefixedKeys[$i] = "\0".get_parent_class($class).'@anonymous'.strrchr($k, "\0");
80+
} elseif ($debugClass !== $class && 1 === strpos($k, $class)) {
81+
$prefixedKeys[$i] = "\0".$debugClass.strrchr($k, "\0");
8182
}
8283
++$i;
8384
}
@@ -93,6 +94,9 @@ public static function castObject(object $obj, string $class, bool $hasDebugInfo
9394
if ($hasDebugInfo && \is_array($debugInfo)) {
9495
foreach ($debugInfo as $k => $v) {
9596
if (!isset($k[0]) || "\0" !== $k[0]) {
97+
if (\array_key_exists(self::PREFIX_DYNAMIC.$k, $a)) {
98+
continue;
99+
}
96100
$k = self::PREFIX_VIRTUAL.$k;
97101
}
98102

Caster/ReflectionCaster.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ private static function addExtra(array &$a, \Reflector $c)
376376
private static function addMap(array &$a, \Reflector $c, array $map, string $prefix = Caster::PREFIX_VIRTUAL)
377377
{
378378
foreach ($map as $k => $m) {
379+
if (\PHP_VERSION_ID >= 80000 && 'isDisabled' === $k) {
380+
continue;
381+
}
382+
379383
if (method_exists($c, $m) && false !== ($m = $c->$m()) && null !== $m) {
380384
$a[$prefix.$k] = $m instanceof \Reflector ? $m->name : $m;
381385
}

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, b
162162
return $a;
163163
}
164164

165-
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, bool $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, bool $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'],
@@ -285,8 +284,8 @@ protected function castObject(Stub $stub, bool $isNested)
285284
$obj = $stub->value;
286285
$class = $stub->class;
287286

288-
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
289-
$stub->class = get_parent_class($class).'@anonymous';
287+
if (\PHP_VERSION_ID < 80000 ? "\0" === ($class[15] ?? null) : false !== strpos($class, "@anonymous\0")) {
288+
$stub->class = get_debug_type($obj);
290289
}
291290
if (isset($this->classInfo[$class])) {
292291
list($i, $parents, $hasDebugInfo, $fileInfo) = $this->classInfo[$class];
@@ -315,7 +314,7 @@ protected function castObject(Stub $stub, bool $isNested)
315314
}
316315

317316
$stub->attr += $fileInfo;
318-
$a = Caster::castObject($obj, $class, $hasDebugInfo);
317+
$a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class);
319318

320319
try {
321320
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
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20-
"symfony/polyfill-mbstring": "~1.0"
20+
"symfony/polyfill-mbstring": "~1.0",
21+
"symfony/polyfill-php80": "^1.15"
2122
},
2223
"require-dev": {
2324
"ext-iconv": "*",

0 commit comments

Comments
 (0)