- [x] I was not able to find an open or closed issue matching what I'm seeing.
- [x] This is not a question. (Questions should be asked on chat (Signup here) or our forums.)
The Zend\ServiceManager\Di\DiAbstractServiceFactory
when used as an abstract factory is causing recursion.
The issue is caused by Zend\ServiceManager\ServiceManager::has()
function implementation and Zend\ServiceManager\Di\DiAbstractServiceFactoryFactory: :__invoke()
function which is using DiAbstractServiceFactory::USE_SL_BEFORE_DI
and Zend\ServiceManager\Di\DiServiceFactory: :get()
method which is sending the object initialization request back to the Zend\ServiceManager\ServiceManager
and as a result creating the recursion.
During object initialization by ServiceManager
via DiAbstractServiceFactory
the DiServiceFactory::get()
method checks whether it should call ServiceManager
(Service Locator) first by the following code (line 126) and therefore sends the object initialization request back to the ServiceManager
because both conditions for the if statement are correct in this situation.
// Allow this di service to get dependencies from the service locator BEFORE trying DI.
if ($this->useContainer === self::USE_SL_BEFORE_DI && $this->container->has($name)) {
return $this->container->get($name);
}
As the object initialization request is sent or pushed back to the ServiceManager
and the ServiceManager
will forward the request again to DiAbstractServiceFactory
therefore creating the recursion (sending the request back and forth) and the end result is system memory exhausted.
Code to reproduce the issue
Please just use Zend\ServiceManager\Di\DiAbstractServiceFactory
as an abstract factory
and then use ServiceManager
to get/initialize an object. This object should not have any other factory class defined in the config. The only factory which should initialize this object should be Zend\ServiceManager\Di\DiAbstractServiceFactory
.
Expected results
No Recursion.
Actual results
Recursion
Originally posted by @mirza572 at https://github.com/zendframework/zend-servicemanager-di/issues/19