diff --git a/src/Symfony/Component/DependencyInjection/Argument/LazyClosure.php b/src/Symfony/Component/DependencyInjection/Argument/LazyClosure.php index 658414e0d8635..230363a95bf3a 100644 --- a/src/Symfony/Component/DependencyInjection/Argument/LazyClosure.php +++ b/src/Symfony/Component/DependencyInjection/Argument/LazyClosure.php @@ -88,7 +88,7 @@ public static function getCode(string $initializer, array $callable, Definition } $code = 'new class('.$initializer.') extends \\'.self::class - .$code.' { '.($methodReflector->getReturnType() instanceof \ReflectionNamedType && 'void' === $methodReflector->getReturnType()->getName() ? '' : 'return ').'$this->service->'.$callable[1].'('.$args.'); } ' + .$code.' { '.($methodReflector->hasReturnType() && 'void' === (string) $methodReflector->getReturnType() ? '' : 'return ').'$this->service->'.$callable[1].'('.$args.'); } ' .'}'; return $asClosure ? '('.$code.')->'.$method.'(...)' : $code;