Autoloading inheritance issue with abstract classes [Symfony 6.1 & PHP8.1] #48295
Unanswered
MenschLennart
asked this question in
Q&A
Replies: 1 suggested answer
-
Are you sure you don't just reference an inexisting Else we would need a reproducer in order to investigate. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{{editor}}'s edit
{{editor}}'s edit
Loading...
Sorry, something went wrong.
-
Hello everyone,
Symfony's dependency injection can't properly resolve class inheritance and thus resolves an error that occurs from time to time. I suspect it is related to the cache.
Symfony 6.1 & PHP8.1
The error occurs in all test environments.
If it contributes to the error, please know that we have anonymised the namespace. We use a custom namespace that is set via composer.json.
The following exception is thrown. This also crashes the PHP service and restarts it automatically.
What we want to do
With the DialogService, the respective class with the DI is to be created via function and the class name as parameter.
Briefly. We are aware that inserting the container is not best practice - but we decided to do it here because we want to build classes dynamically. We are sure there are better ways and means to do this. But we still want to discuss this issue here with you.
service.yaml
We added a new entry for all Dialogs under a new namespace like described here because since we inject the container we need to set them to be public.
In addition, we use the Calls function to set the container in the DialogService.
Dialog (abstract class)
Abstract class with standard functions like getters and setters from which all *Dialog classes inherit.
ContractCheckDialog.php (inheritance class)
The Class we want to autoload via
$this->container->get($class)
inside of the DialogService.This Class is using the PHP 8 #[Required] annotation component implemented with Symfony 6
DialogService
This service is getting the container via ContainerAwareTrait and use it to dynamically create the class
with
$this->container->get($class);
Have we configured the service.yaml incorrectly? Or are we doing something wrong elsewhere? We would be very happy to hear your ideas about this, because so far we have not been able to delete it and find the causes of the problem.
Beta Was this translation helpful? Give feedback.