title: php - Using type hinting and dependency injection
body: <p>I'm using <a href="http://php.net/manual/en/language.oop5.typehinting.php" rel="nofollow">Type Hinting</a> on a class that gets passed an object into its constructor. The passed object (Bar) exists in its own namespace. This is all fine until I swap out the passed object with a fake one (for unit testing purposes). My test Bar object resides in its own namespace and now an error is (quite rightly) thrown.</p>
  
  <pre><code>use Some\Place\Bar
  class Foo {
      // Passing a test Bar into here now throws error.
      public function __construct(Bar $bar) {
          $this-&gt;bar = $bar;
      }
  
  }
  </code></pre>
  
  <p>I'm new to PHP so unsure on what is possible. Is there a way round this or do I just need to drop Type Hinting from the class (which is my current solution)?</p>