title: PHP - if autoloading, why would you use dependancy injection?
body: <p>Please forgive the possible naivety of this question, however I am getting myself really confused. It appears that it is good practice to use dependancy injection to decouple your code so that your classes are loaded with their dependancies. PLease imagine the following where Class Foo has a dependancy of class Bar</p>
  
  <pre><code>namespace Classes;
  
  class Foo{
  
      protected barInstance;
  
      public function __construct(Bar $barInstance){
          $this-&gt;barInstance=$barInstance;
      }
  
  }
  </code></pre>
  
  <p>However if you are autoloading your classes then surely the following does the exact same thing without the need of DI?</p>
  
  <pre><code>namespace Classes;
  use Classes/Bar;
  
  class Foo{
  
      protected barInstance;
  
      public function __construct(){
          $this-&gt;barInstance=new Bar;
      }
  
  }
  </code></pre>
  
  <p>Thanks to any responders.</p>