Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handle Lazy Loading Initialization Failures #8875

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

Closed
jeremylivingston opened this issue Aug 28, 2013 · 1 comment
Closed

Handle Lazy Loading Initialization Failures #8875

jeremylivingston opened this issue Aug 28, 2013 · 1 comment

Comments

@jeremylivingston
Copy link
Contributor

The current lazy loading code sets the initializer to null before the instance is initialized.

Code references RuntimeInstantiator (also in ProxyDumper):

public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
{
    return $this->factory->createProxy(
        $definition->getClass(),
        function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) {
            $proxy->setProxyInitializer(null);

            $wrappedInstance = call_user_func($realInstantiator);

            return true;
        }
    );
}

In cases where the constructor for this object throws an exception, subsequent method calls on this object will attempt to call a null object.

I feel that the ProxyInitializer should be set to null after the object is initialized. This way other method calls will attempt to initialize the object again if the exception was caught elsewhere.

@Ocramius
Copy link
Contributor

Makes sense in this particular case. +1

fabpot added a commit that referenced this issue Aug 29, 2013
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #8877).

Discussion
----------

Clear lazy loading initializer after the service is successfully initialized

Fixes #8875

Commits
-------

da73102 Clear lazy loading initializer after the service is successfully initialized
@fabpot fabpot closed this as completed Aug 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants