We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Mongo: Maximum recursion depth exceeded

I'm brand spanking new at Phalcon and working on getting Mongo connected to a remote host. I seem to be connected to the db but trying to instantiate the model that extends \Phalcon\Mvc\Collection gives me the following error.

Fatal error: Phalcon\DI::get(): Maximum recursion depth exceeded

Any help is appreciated.

Show your code

edited Mar '14

The connection to mongo in the bootstrap is:

$di->set('mongo', function() {
    $config = Registry::get(CONFIG);
    $connect = array('username' => $config->mongo->username,
                     'password' => $config->mongo->password );
    $mongo = new Mongo($config->mongo->host, $connect);
    return $mongo->selectDb($config->mongo->name);
}, TRUE);
$di->set('collectionManager', '\Phalcon\Mvc\Collection');

In the controller I've tried

$user = User::find();

which shows: Fatal error: Phalcon\DI::get(): Maximum recursion depth exceeded

$user = new User();

Which shows the error: Fatal error: Phalcon\DI\Service::resolve(): Maximum recursion depth exceeded

The User model is simply

class User extends \Phalcon\Mvc\Collection
{

}


98.9k
edited Oct '14

This kind of fatal error is raised when the extension detects an infinite loop. Infine loops could make the execution unstable because PHP could be out of memory. Try adding a debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) in the 'mongo' and 'collectionManager' service definition to check if there is a cyclic dependency in one of your services.



5.1k
Accepted
answer
edited Oct '14

Turned out that I needed to add Manager to:

$di->set('collectionManager', '\Phalcon\Mvc\Collection\Manager');