Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

DiAbstractServiceFactory Recursion #19

Open
@mirza572

Description

@mirza572
  • I was not able to find an open or closed issue matching what I'm seeing.
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions