8000 avoid (string) catchable fatal error for instances of __PHP_Incomplet… · symfony/symfony@4b7ed98 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 4b7ed98

Browse files
ycerutofabpot
authored andcommitted
avoid (string) catchable fatal error for instances of __PHP_Incomplete_Class
1 parent 4598b74 commit 4b7ed98

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function exportValue($value, $depth = 1, $deep = false)
3535
return sprintf('Object(%s)', get_class($value));
3636
}
3737

38+
if ($value instanceof \__PHP_Incomplete_Class) {
39+
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
40+
}
41+
3842
if (is_array($value)) {
3943
if (empty($value)) {
4044
return '[]';
@@ -75,4 +79,11 @@ public function exportValue($value, $depth = 1, $deep = false)
7579

7680
return (string) $value;
7781
}
82+
83+
private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
84+
{
85+
$array = new \ArrayObject($value);
86+
87+
return $array['__PHP_Incomplete_Class_Name'];
88+
}
7889
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public function testDateTimeImmutable()
3939
$dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
4040
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
4141
}
42+
43+
public function testIncompleteClass()
44+
{
45+
$foo = new \__PHP_Incomplete_Class();
46+
$array = new \ArrayObject($foo);
47+
$array['__PHP_Incomplete_Class_Name'] = 'AppBundle/Foo';
48+
$this->assertSame('__PHP_Incomplete_Class(AppBundle/Foo)', $this->valueExporter->exportValue($foo));
49+
}
4250
}

0 commit comments

Comments
 (0)
0