Skip to content

Commit f702d1e

Browse files
[VarDumper] fix dumping uninitialized SplFileInfo
1 parent e7f7041 commit f702d1e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe
9090

9191
$prefix = Caster::PREFIX_VIRTUAL;
9292

93+
if (false === $c->getPathname()) {
94+
$a[$prefix.''] = 'The parent constructor was not called: the object is in an invalid state';
95+
96+
return $a;
97+
}
98+
9399
foreach ($map as $key => $accessor) {
94100
try {
95101
$a[$prefix.$key] = $c->$accessor();

src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ public function testArrayIterator()
202202
0 => 234
203203
]
204204
}
205+
EOTXT;
206+
$this->assertDumpEquals($expected, $var);
207+
}
208+
209+
public function testBadSplFileInfo()
210+
{
211+
if (\defined('HHVM_VERSION')) {
212+
$this->markTestSkipped('HHVM as different internal details.');
213+
}
214+
$var = new BadSplFileInfo();
215+
216+
$expected = <<<EOTXT
217+
Symfony\Component\VarDumper\Tests\Caster\BadSplFileInfo {
218+
⚠: "The parent constructor was not called: the object is in an invalid state"
219+
}
205220
EOTXT;
206221
$this->assertDumpEquals($expected, $var);
207222
}
@@ -211,3 +226,10 @@ class MyArrayIterator extends \ArrayIterator
211226
{
212227
private $foo = 123;
213228
}
229+
230+
class BadSplFileInfo extends \SplFileInfo
231+
{
232+
public function __construct()
233+
{
234+
}
235+
}

0 commit comments

Comments
 (0)