how dependency injection and container develop

reference : http://jaceju.net/2014-07-27-php-di-container/

why we need dependency injection ?
cause we want to remove  dependency. Instead of creating object in the inner, we pass the object via parameter during construction.

if we want to change the way we auth or how session store, we may need to change class app too.

much better now,and we want different ways to auth,we had better to change auth to interface

looks great, then why we need the container?
sometimes we don’t know which way we want until we run the program.(http or db auth). we can register the class we want into a container,and retrieve later.

looks perfect,but every time we need to create an app object,we need to write all this code. it’s a wise choice to wrap them into a function.

could we make it better?
yes,we can. Every time we create an app object, we have to inject the dependency into container. what if the container can auto load the dependency by itself, then we can free from providing the dependency. it’s time to present reflection class.
http://php.net/manual/en/class.reflectionclass.php

holy shit,only one line code we got what we want.