avoid (string) catchable fatal error for instances of __PHP_Incomplete_Class
This commit is contained in:
parent
4598b74906
commit
4b7ed987dd
@ -35,6 +35,10 @@ class ValueExporter
|
||||
return sprintf('Object(%s)', get_class($value));
|
||||
}
|
||||
|
||||
if ($value instanceof \__PHP_Incomplete_Class) {
|
||||
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
if (empty($value)) {
|
||||
return '[]';
|
||||
@ -75,4 +79,11 @@ class ValueExporter
|
||||
|
||||
return (string) $value;
|
||||
}
|
||||
|
||||
private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
|
||||
{
|
||||
$array = new \ArrayObject($value);
|
||||
|
||||
return $array['__PHP_Incomplete_Class_Name'];
|
||||
}
|
||||
}
|
||||
|
@ -39,4 +39,12 @@ class ValueExporterTest extends \PHPUnit_Framework_TestCase
|
||||
$dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
|
||||
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
|
||||
}
|
||||
|
||||
public function testIncompleteClass()
|
||||
{
|
||||
$foo = new \__PHP_Incomplete_Class();
|
||||
$array = new \ArrayObject($foo);
|
||||
$array['__PHP_Incomplete_Class_Name'] = 'AppBundle/Foo';
|
||||
$this->assertSame('__PHP_Incomplete_Class(AppBundle/Foo)', $this->valueExporter->exportValue($foo));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user