title: Pass variable number of params without call_user_func_array()
body: <p>I have a code problem which stems from the fact that I am using certain libraries of code I cannot change.</p>
  
  <p>I use the following code to pass execution of any undefined methods to another class, and it works fine but it seems like a waste doubling up.</p>
  
  <p>Any suggestions?</p>
  
  <p>Basically I want to know if it's possible to pass an unknown number of parameters to a method (without using <code>call_user_func_array()</code>, just in case they need to be passed by reference). I am not asking how to use <code>func_get_args()</code>, rather the reverse.</p>
  
  <p>Or should I just allow for a few more arguments in the first logic path (the <code>list()</code> code)?</p>
  
  <pre><code>class Foo {
      __construct() {
          $this-&gt;external = new ClassThatIHaveNoControlOver();
      }
  
      function bar($name) {
          return 'Hi '.$name;
      }
  
      function __call($method, $arguments) {
          if (count($arguments) &lt; 3) {
              // call_user_func_array won't pass by reference, as required by
              // ClassThatIHaveNoControlOver-&gt;foobar(), so calling the function
              // directly for up to 2 arguments, as I know that foobar() will only
              // take 2 arguments
              list($first, $second) = $arguments + Array(null, null);
              return $this-&gt;external-&gt;$method($first, $second);
          } else {
              return call_user_func_array(array($this-&gt;external, $method), $arguments);
          }
      }
  }
  
  $foo = new Foo();
  
  $firstName = 'Bob';
  $lastName = 'Brown';
  echo $foo-&gt;bar($firstName); // returns Hi Bob as expected
  echo $foo-&gt;foobar($firstName, $lastName); // returns whatever
          // ClassThatIHaveNoControlOver()-&gt;foobar() is meant to return
  </code></pre>
  
  <p><strong>EDIT</strong>
  Just to clarify, I know I can use <a href="http://ca.php.net/manual/en/mysqli-stmt.bind-param.php#96770" rel="nofollow">this</a> method to rejig the parameters as references, but that would mean passing everything as a reference, even if the method didn't require it - something I was trying to avoid, but seems unlikely at the moment.</p>