-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected: 4.2
Description
Given a class implementing \Serializable
, if the serialize
is called on a badly constructed instance and throws a \TypeError, then the Registry::getClassReflector
failed because of https://github.com/symfony/symfony/blob/master/src/Symfony/Component/VarExporter/Internal/Registry.php#L101 .
How to reproduce
class Foo implements \Serializable
{
$foo;
public function __construct(string $foo) {$this->foo = $foo;}
public function getFoo(): string {return $this->foo;} // throws a TypeError if $this->foo is null
public function serialize(): string { return [$this->getFoo()]; }
public function unserialize(string $str): { [$this->foo] = \unserialize($str); }
}
Possible Solution
Note that catching \Throwable
in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/VarExporter/Internal/Registry.php#L105 could solve the issue, but would replace serialization by a PropertyAccess hydration which is much more slower