[VarExporter] unserialize() might throw an Exception on php 8.

This commit is contained in:
Alexander M. Turek 2020-09-07 21:30:36 +02:00
parent fff8c001e6
commit 65112e11bc
2 changed files with 14 additions and 4 deletions

View File

@ -13,8 +13,8 @@ namespace Symfony\Component\VarExporter\Exception;
class NotInstantiableTypeException extends \Exception implements ExceptionInterface
{
public function __construct(string $type)
public function __construct(string $type, \Throwable $previous = null)
{
parent::__construct(sprintf('Type "%s" is not instantiable.', $type));
parent::__construct(sprintf('Type "%s" is not instantiable.', $type), 0, $previous);
}
}

View File

@ -89,8 +89,18 @@ class Registry
$proto = $reflector->implementsInterface('Serializable') && !method_exists($class, '__unserialize') ? 'C:' : 'O:';
if ('C:' === $proto && !$reflector->getMethod('unserialize')->isInternal()) {
$proto = null;
} elseif (false === $proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}')) {
throw new NotInstantiableTypeException($class);
} else {
try {
$proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}');
} catch (\Exception $e) {
if (__FILE__ !== $e->getFile()) {
throw $e;
}
throw new NotInstantiableTypeException($class, $e);
}
if (false === $proto) {
throw new NotInstantiableTypeException($class);
}
}
}
if (null !== $proto && !$proto instanceof \Throwable && !$proto instanceof \Serializable && !method_exists($class, '__sleep') && (\PHP_VERSION_ID < 70400 || !method_exists($class, '__serialize'))) {