-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fatal error during upgrading to Symfony 7.3 and rebuilding container: Uncaught Error: First array member is not a valid class name or object #60585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The main issue here is that symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php Lines 79 to 81 in e9f91a6
Based on the discussion there, this was intentional, so I'm not sure it qualifies as a bug, even though it is technically a BC break. |
It makes sense that this does not work anymore if it has explicitly been removed. But I'd expect that minor upgrades do not introduce these kind of breaking changes? |
so it's expected yes. |
It's indeed removed but
Anyway, worked my way around this by referencing the FQCN instead of |
As a workaround you can disable autoconfiguration for that definition: App\Infrastructure\ValueObject\Measurement\UnitSystem:
autoconfigure: false
factory: [ null, from ]
arguments: ['@=app_config("appearance.unit_system")'] |
This is how it works by design indeed. I get the BC aspect of this. Changing the behavior of the app is something that's inherent to autoconfiguration. Of course, we're careful not to break anything as much as possible, but I see little alternatives here. We could find a way to track explicitly-defined services and never auto-exclude them. But that introduces an exception to the rules of autoconfiguration so this might be hard to justify on the long run. We might also make a special case for enums only, where the autoconfiguration rule is replaced by some similar logic in the FileLoader that does the auto-discovery. Dunno if any of these options make sense. I'd be tempted to close as "won't fix" unless we gather more feedback on the topic. (who else is using an enum class as a service? please let us know if this is common enough practive.) |
For me this issue can be closed, the My use case for using enums as a service is a self-hosted app running in a docker container. Users can configure this app by means of several |
I see the issue is already closed. But to give some insight in this, we apply a string enum as a service (with the same factory pattern as described above) as a better alternative to injecting a raw string value. That enum also has a few convenience methods so we don't have to do string comparison everywhere. |
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
7.3.0
Description
When running
composer update symfony/*
to upgrade from 7.2 to 7.3, all packages are downloaded and installed. When composer tries to clear the Symfony cache and the container is rebuilt, the following error is thrown:Line 799 contains:
The error is thrown due to the first value in the array
NULL
. The reason for NULL being there is that my service is defined as:How to reproduce
services.yaml
with a factory method on the class itself:composer.json
and edit all Symfony packages from7.2.*
to7.3.*
composer update symfony/*
Possible Solution
No response
Additional Context
The Symfony docs state that this approach should be possible: https://symfony.com/doc/current/service_container/factories.html#using-the-class-as-factory-itself
The text was updated successfully, but these errors were encountered: