Skip to content
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

Container::buildObject may result in infitite loop #4

Closed
piotr-cz opened this issue Apr 10, 2014 · 4 comments
Closed

Container::buildObject may result in infitite loop #4

piotr-cz opened this issue Apr 10, 2014 · 4 comments

Comments

@piotr-cz
Copy link
Contributor

The buildObject method uses set method at the bottom.

In specific case this may lead to infinite loop of
Joomla\DI\Container->buildObject() and Joomla\DI\Container->getMethodArgs() methods resulting in
Fatal error: Maximum function nesting level of '100' reached, aborting!

Because same key is being set in two places at a time:

$fqcn = '\\Extension\\vendor\\FooComponent\\FooComponent';
$data = array();

$container->set(
    $fqcn,
    function (Container $c) use ($fqcn, $data)
    {
        $instance = $c->buildObject($fqcn);
        $instance->setData($data);

        return $instance;
    }
);

I'm not sure if this is a bug (I'd say the set method shouldn't be part of the buildObject) or I misunderstood the functionality.

@dongilbert
Copy link
Contributor

Can you send me the code that causes this so I can better debug?

@piotr-cz
Copy link
Contributor Author

nibra added a commit to nibra/di that referenced this issue Aug 6, 2015
buildObject now detects circular dependencies and throws an exception
@nibra
Copy link
Contributor

nibra commented Aug 6, 2015

The problem is not caused by the call to set(), but by a circular dependency. $fqcn has to be resolved in order to resolve $fqcn, which leads to an endless loop.

There's no way to get around this; however, buildObject() can be changed to detect that and throw an exception. I solved that already in my repo, PR comes when I'm done with the documentation.

@nibra nibra mentioned this issue Aug 7, 2015
@mbabker
Copy link
Contributor

mbabker commented Feb 25, 2018

Fixed via 33c66e4 for 1.x (by backporting appropriate changes from #16).

@mbabker mbabker closed this as completed Feb 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants