Skip to content

[DependencyInjection] Autowire attribute does not work for nullable parameters #49370

Closed
@derrabus

Description

@derrabus

Symfony version(s) affected

6.2.6

Description

If I try to autowire a parameter value into a service using the #[Autowire] attribute, autowiring fails if that parameter is null. The exception tells me to configure that constructor parameter explicitly. Changing the parameter to a value other than null makes the exception disappear.

How to reproduce

# services.yaml

parameters:
    my_parameter: null
final class MyService
{
    public function __construct(
        #[Autowire('%my_parameter%')]
        private ?string $myParameter,
    ) {
    }
}

Possible Solution

No response

Additional Context

No response

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