ramiromd
ramiromd

Reputation: 2029

What is wrong with this closure?

I have the next code snippet:

$di = new FactoryDefault();
...
$di->setShared('mongo', function($di) use ($di) {
   return new Models\MongoDb\Manager($di);
});

The code works fine, but PHP log says:

Warning:  Missing argument 1 for {closure}() in
/var/www/merkaz.gq/public_html/v1/index.php on line 63

Any ideas ?

Upvotes: 0

Views: 122

Answers (2)

serghei
serghei

Reputation: 3381

In Phalcon 2.1 you can use:

$di->setShared('mongo', function() {
   return new Models\MongoDb\Manager($this);
});

Upvotes: 1

Federkun
Federkun

Reputation: 36964

Because your clousure is not called with the $di argument. Change

function($di) use ($di) {

to

function() use ($di) {

Upvotes: 2

Related Questions