8000 Fixed (string) catchable fatal error for PHP Incomplete Class instances by yceruto · Pull Request #17691 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function exportValue($value, $depth = 1, $deep = false)
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 '[]';
Expand Down Expand Up @@ -75,4 +79,11 @@ public function exportValue($value, $depth = 1, $deep = false)

return (string) $value;
}

private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
{
$array = new \ArrayObject($value);

return $array['__PHP_Incomplete_Class_Name'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant u just access this as a property without arrayobject?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$foo = new \__PHP_Incomplete_Class();
echo $foo->__PHP_Incomplete_Class_Name;

results in:

The script tried to execute a method or access a property of an incomplete object.
Please ensure that the class definition "unknown" of the object you are trying to
operate on was loaded _before_ unserialize() gets called or provide a __autoload()
function to load the class definition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, __PHP_Incomplete_Class is really weird (the fact that is_object returns false for it is a first WTF, but not the only one)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ public function testDateTimeImmutable()
$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));
}
}
0