jeudi 18 mai 2017

How to use injection class in php?

I have class:

class MongoConnection
{

    private $_m;

    private $_db;

    private $_collection;

    public function _connect($dbname, $dbcollection)
    {
    }

}

In another class I want to use this as:

class Object {

private $collection;


public function __construct(MongoConnection $mongoConnection)
{

   $mongoConnection->_connect("", "");
}

}

But it does not work for me. I get an error:

Catchable fatal error: Argument 1 passed to Object::__construct() must be an instance of MongoConnection, none given, called in

Aucun commentaire:

Enregistrer un commentaire