how to use a DI Container
I'm trying to understand how to use a DI Container.

Let's say I have three classes : A, B, and C defined like so :

    class A {}

    class B
    {
        private $a;

        public function set_a(A $a)
        {
            $this->a = $a;
        }
    }

    class C
    {
        private $b;

        public function set_b(B $b)
        {
            $this->b = $b;
        }
    }

Now what I don't really get, is what I am supposed to write in index.php. I've read it's not a good thing to instantiate a Container and then pass it to my objects so that they can use it because it makes my objects dependent on the container. But does it mean, then, that I must write something like this in index.php :

    $container = new Container();
    $container->a = function($ctnr) {
        return new A();
    }
    $container->b = function($ctnr) {
        $b = new B();
        $b->set_a($ctnr->a);
        return $b;
    }
    $container->b = function($ctnr) {
        $c = new C();
        $c->set_b($ctnr->b);
        return $c;
    }

    $c = $container->c;

Is this the way to go ?
how to use a DI Container
===

I'm trying to understand how to use a DI Container.

Let's say I have three classes : A, B, and C defined like so :

    class A {}

    class B
    {
        private $a;

        public function set_a(A $a)
        {
            $this->a = $a;
        }
    }

    class C
    {
        private $b;

        public function set_b(B $b)
        {
            $this->b = $b;
        }
    }

Now what I don't really get, is what I am supposed to write in index.php. I've read it's not a good thing to instantiate a Container and then pass it to my objects so that they can use it because it makes my objects dependent on the container. But does it mean, then, that I must write something like this in index.php :

    $container = new Container();
    $container->a = function($ctnr) {
        return new A();
    }
    $container->b = function($ctnr) {
        $b = new B();
        $b->set_a($ctnr->a);
        return $b;
    }
    $container->b = function($ctnr) {
        $c = new C();
        $c->set_b($ctnr->b);
        return $c;
    }

    $c = $container->c;

Is this the way to go ?