Skip to content

list:container reports "Invalid service XYZ, method Factory::method() does not exist" when called via __callStatic. #58614

Closed
@KevinVanSonsbeek

Description

@KevinVanSonsbeek

Symfony version(s) affected

5.4 and up

Description

Back in #44356 this issue was reported for factories using the __call magic method.
This behavior was fxed back then in #44710. The same problem is present for the __callStatic logic however.

I ran into this issue, as we have a service definition of a MyCLabs enum, which uses static calls to create instances of the "enums".

I'm aware that the myclabs/enum package has no real use anymore since php 8.1, but due to the scale of the project we have not had the time yet to transition fully to native enums.

And the discrepancy between the two methods feels like it could've been an oversight when implementing said previous fix.

How to reproduce

use MyCLabs\Enum\Enum;

final class FooBar extends Enum
{
    public const FOO = 'foo_value';
    public const BAR = 'bar_value';
}
<service id="foo_instance" class="FooBar">
    <factory class="FooBar" method="FOO"/>
</service>

<service id="bar_instance" class="FooBar">
    <factory class="FooBar" method="BAR"/>
</service>

Possible Solution

A fix similiar to the one in https://github.com/symfony/symfony/pull/44710/files could be applied for the callStatic as well.

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