title: Inject any of four classes into a class
body: <p>I have a class (lets call it <code>TestClassA</code>) in which the constructor looks something like this</p>
  
  <pre><code>public function __constructor(SomeInterface $some, AnotherInterface $another, $additionalArgs = null)
  {
      // Rest of code
  }
  </code></pre>
  
  <p>The value of <code>$additionalArgs</code> can come from any of four unique classes. Each of these classes will add unique query arguments to the class above according to the user's condition set. Lets name these classes</p>
  
  <ul>
  <li><p>TestB</p></li>
  <li><p>TestC</p></li>
  <li><p>TestD</p></li>
  <li><p>TestE</p></li>
  </ul>
  
  <p>I'm not sure if interface injection will be my best solution here, as, once a condition is set, it will most probably never change again, and only one option can be set at any given time. For example, if the user has decided to use <code>TestC</code> class, the probability that he will change to either of the other three remaining classes is almost zero. So, if I'm correct, if I use interface injection (like in the example below) and add all four classes, I will instantiate 3 classes unnecessarily as they will in most probability never get used</p>
  
  <pre><code>public function __constructor(
      SomeInterface $some, 
      AnotherInterface $another,
      TestBInterface $testB,
      TestCInterface $testC,
      TestDInterface $testD,
      TestEInterface $testE
  ) {
      // Rest of code
  }
  </code></pre>
  
  <p>What I thought of was to create my <code>TestClassA</code> with a property of <code>$additionalArgs</code>, creating a new instance of the required class, lets say <code>TestC</code> and then passing that to the <code>$additionalArgs</code>, which I then use in a method to get the required values. </p>
  
  <p>Example</p>
  
  <pre><code>$a = new SomeClass;
  $b = new AnotherClass;
  $c = new TestC;
  
  $d = new TestClassA($a, $b, $c-&gt;someMethod());
  </code></pre>
  
  <p>My question is, how do I make sure that the value passed to <code>$additionalArgs</code> is a valid instance of one of the four classes that should be passed to this parameter. I have already tried to verify this using <code>instanceof</code> in my method, in this example <code>someMethod()</code> , but the condition fails</p>
  
  <p>Any suggestions on how to address this problem, and still "comply" with basic OOP principles?</p>