10000 [DependencyInjection] Invalid service "Foo\Bar": its constructor must be public · Issue #60593 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[DependencyInjection] Invalid service "Foo\Bar": its constructor must be public #60593
Open
@derrabus

Description

@derrabus

Symfony version(s) affected

7.3.0

Description

I tried to upgrade a codebase to Symfony 7.3 that contains classes that serve merely as a namespace for utility functions, e.g.:

final readonly class MyUtils
{
    public static function doSomething()
    {
        // some logic
    }

    private function __construct() {}
}

Those classes are not meant to be instantiated and they're not wired anywhere. However, wen I try to perform a service autodiscovery on a namespace that hat classes like that, I now get an error:

Invalid service "Foo\Bar": its constructor must be public. Did you miss configuring a factory or a static constructor? Try using the "#[Autoconfigure(constructor: ...)]" attribute for the latter.

Excluding each and every of these classes from the discovery solves this issue, but I would've expected that this error is not raised unless I actually try to wire one of those classes as a service.

How to reproduce

I'll try to come up with a reproducer soon.

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

      0