title: How to write and use a PHP Dependency Injection Conatiner using PHP Reflection API
body: <p>I'm trying to implement a simple DI in a pure OOP application. I wanted to use Dependency injection to manage many services ( Database, RequestValidator, Cache etc. ). I have read many blogs and liked <a href="https://medium.com/tech-tajawal/dependency-injection-di-container-in-php-a7e5d309ccc6" rel="nofollow noreferrer">this one from tech-tajawal</a> but I could not really understand where should I include <a href="https://gist.github.com/MustafaMagdi/2bb27aebf6ab078b1f3e5635c0282fac" rel="nofollow noreferrer">the container that tech-tajawal wrote</a>. Can someone please show me how to do it?</p>
  
  <p>I want it clean and thus want to use constructor based injection. So If I have a class, let's say <code>AbstractBaseController</code> which will inject a dependency called <code>Request</code>, so I will write:</p>
  
  <p><strong>php:</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
       namespace src\controllers;
       use system\middlewares\Request as Request;
  
       abstract class AbstractBaseController {
  
           private $request;
  
           public function __construct(Request $request) {
               $this-&gt;request = $request;
               return $this;
           }
  
       }
  </code></pre>
  
  <p>But this simply throws        </p>
  
  <blockquote>
    <p>Fatal error: Uncaught TypeError: Argument 1 passed to src\controllers\AbstractBaseController::__construct() must be an instance of system\middlewares\Request, none given`</p>
  </blockquote>
  
  <p>I think <a href="https://gist.github.com/MustafaMagdi/2bb27aebf6ab078b1f3e5635c0282fac" rel="nofollow noreferrer">the container from tech-tajawal</a> has to be included in my project root someway but I don't know how. </p>
  
  <p>Please excuse my naivety here as I always was framework dependent.</p>