Skip to content

PHP 8 support issue in handling of current() factories in DI #39737

@Seldaek

Description

@Seldaek

Symfony version(s) affected: 4.4.18

Description

parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s()" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $acceptedType, $type));
does not support ReflectionParameter which are on a function and not a class. $parameter->getDeclaringClass()->getName() fails because getDeclaringClass returns null.

This only happens on PHP 8 because

using current in PHP 8 will result in a parameter type hint being array|object, while PHP 7 did not have a type hint: https://3v4l.org/YKHtO and apparently Symfony also does not support union types as per @nicolas-grekas.

How to reproduce
I could not reduce it to a minimal repro case sorry

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