avoid (string) catchable fatal error for instances of __PHP_Incomplete_Class

This commit is contained in:
Yonel Ceruto 2016-02-04 15:06:04 -05:00 committed by Fabien Potencier
parent 4598b74906
commit 4b7ed987dd
2 changed files with 19 additions and 0 deletions

View File

@ -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'];
}
}

View File

@ -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));
}
}