Skip to content

[VarExporter] export failure when object requires a constructed object #29570

@jderusse

Description

@jderusse

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions