8000 bug #38073 [VarDumper] Fix caster for invalid SplFileInfo objects on … · symfony/symfony@ee8fc9c · GitHub
[go: up one dir, main page]

Skip to content

Commit ee8fc9c

Browse files
committed
bug #38073 [VarDumper] Fix caster for invalid SplFileInfo objects on php 8 (derrabus)
This PR was merged into the 3.4 branch. Discussion ---------- [VarDumper] Fix caster for invalid SplFileInfo objects on php 8 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #36872 | License | MIT | Doc PR | N/A The behavior of uninitialized `SplFileInfo` classes has changed in php 8: https://3v4l.org/s4c4O * `getPathname()` won't return `false` anymore. * The error raised by most accessors is now recoverable. On php 7, it's fatal. This PR adjusts the caster for those objects to the new behavior. Commits ------- ab45e2a [VarDumper] Fix caster for invalid SplFileInfo objects on php 8.
2 parents 63eab44 + ab45e2a commit ee8fc9c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Symfony/Component/VarDumper/Caster/SplCaster.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,24 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe
9292
unset($a["\0SplFileInfo\0fileName"]);
9393
unset($a["\0SplFileInfo\0pathName"]);
9494

95-
if (false === $c->getPathname()) {
96-
$a[$prefix.''] = 'The parent constructor was not called: the object is in an invalid state';
95+
if (\PHP_VERSION_ID < 80000) {
96+
if (false === $c->getPathname()) {
97+
$a[$prefix.''] = 'The parent constructor was not called: the object is in an invalid state';
9798

98-
return $a;
99+
return $a;
100+
}
101+
} else {
102+
try {
103+
$c->isReadable();
104+
} catch (\RuntimeException $e) {
105+
if ('Object not initialized' !== $e->getMessage()) {
106+
throw $e;
107+
}
108+
109+
$a[$prefix.''] = 'The parent constructor was not called: the object is in an invalid state';
110+
111+
return $a;
112+
}
99113
}
100114

101115
foreach ($map as $key => $accessor) {

0 commit comments

Comments
 (0)
0