bug #17691 Fixed (string) catchable fatal error for PHP Incomplete Class instances (yceruto)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #17691).

Discussion
----------

Fixed (string) catchable fatal error for PHP Incomplete Class instances

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17586
| License       | MIT
| Doc PR        |  -

Commits
-------

4b7ed98 avoid (string) catchable fatal error for instances of __PHP_Incomplete_Class
This commit is contained in:
Fabien Potencier 2016-02-12 07:25:11 +01:00
commit ca6f1f7428
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));
}
}