8000 [VarExporter] unserialize() might throw an Exception on php 8. · symfony/symfony@65112e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65112e1

Browse files
committed
[VarExporter] unserialize() might throw an Exception on php 8.
1 parent fff8c00 commit 65112e1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Symfony/Component/VarExporter/Exception/NotInstantiableTypeException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
class NotInstantiableTypeException extends \Exception implements ExceptionInterface
1515
{
16-
public function __construct(string $type)
16+
public function __construct(string $type, \Throwable $previous = null)
1717
{
18-
parent::__construct(sprintf('Type "%s" is not instantiable.', $type));
18+
parent::__construct(sprintf('Type "%s" is not instantiable.', $type), 0, $previous);
1919
}
2020
}

src/Symfony/Component/VarExporter/Internal/Registry.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,18 @@ public static function getClassReflector($class, $instantiableWithoutConstructor
8989
$proto = $reflector->implementsInterface('Serializable') && !method_exists($class, '__unserialize') ? 'C:' : 'O:';
9090
if ('C:' === $proto && !$reflector->getMethod('unserialize')->isInternal()) {
9191
$proto = null;
92-
} elseif (false === $proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}')) {
93-
throw new NotInstantiableTypeException($class);
92+
} else {
93+
try {
94+
$proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}');
95+
} catch (\Exception $e) {
96+
if (__FILE__ !== $e->getFile()) {
97+
throw $e;
98+
}
99+
throw new NotInstantiableTypeException($class, $e);
100+
}
101+
if (false === $proto) {
102+
throw new NotInstantiableTypeException($class);
103+
}
94104
}
95105
}
96106
if (null !== $proto && !$proto instanceof \Throwable && !$proto instanceof \Serializable && !method_exists($class, '__sleep') && (\PHP_VERSION_ID < 70400 || !method_exists($class, '__serialize'))) {

0 commit comments

Comments
 (0)
0