Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f2c68f

Browse filesBrowse files
committed
bug #36794 [Serializer] fix issue with PHP 8 (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Serializer] fix issue with PHP 8 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - The current logic is a bit strange but I guess it's some legacy from PHP 5. This keeps the current behavior while skipping the use of `ReflectionParameter::getClass()`, which [is deprecated in PHP 8](http://git.php.net/?p=php-src.git;a=commitdiff;h=28af364d2ae2261addc21f8830f175baa8fa72cf). Commits ------- 44b45cb [Serializer] fix issue with PHP 8
2 parents a8cb3cd + 44b45cb commit 8f2c68f
Copy full SHA for 8f2c68f

File tree

Expand file treeCollapse file tree

1 file changed

+11
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-3
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,19 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
386386
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)
387387
{
388388
try {
389-
if (null !== $parameter->getClass()) {
389+
if (\PHP_VERSION_ID < 70100 && null !== $parameterClass = $parameter->getClass()) {
390+
$parameterClass = $parameterClass->name;
391+
} elseif (\PHP_VERSION_ID >= 70100 && $parameter->hasType() && ($parameterType = $parameter->getType()) && !$parameterType->isBuiltin()) {
392+
$parameterClass = $parameterType->getName();
393+
new \ReflectionClass($parameterClass); // throws a \ReflectionException if the class doesn't exist
394+
} else {
395+
$parameterClass = null;
396+
}
397+
398+
if (null !== $parameterClass) {
390399
if (!$this->serializer instanceof DenormalizerInterface) {
391-
throw new LogicException(sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameter->getClass(), static::class));
400+
throw new LogicException(sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameterClass, static::class));
392401
}
393-
$parameterClass = $parameter->getClass()->getName();
394402

395403
return $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
396404
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.