title: Adding null values to an array
body: <p>I have the this method:</p>
  
  <pre><code>public function search($searchKey=null, $summary=null, $title=null, $authors=null, $paginationPage=0) { 
      ... 
  }
  </code></pre>
  
  <p>And I'm trying to retrieve all parameters with this:</p>
  
  <pre><code>$Class = new Search();
  
  // Get parameters
  $ReflectionMethod = new \ReflectionMethod($Class, "search");
  try {
      foreach($ReflectionMethod-&gt;getParameters() AS $Parameter) {
          if(array_key_exists($Parameter-&gt;name, $this-&gt;params)) {
              $parameters[$Parameter-&gt;name] = $this-&gt;params[$Parameter-&gt;name];
      } elseif($Parameter-&gt;isDefaultValueAvailable()) {
          $paramaters[$Parameter-&gt;name] = $Parameter-&gt;getDefaultValue();
      } else {
              ...
      }
  } catch(\Exception $e) {
          ...
  }
      // Call function
  return call_user_func_array(array($Class, "search"), $parameters);
  </code></pre>
  
  <p>My <code>$this-&gt;params</code> has this content:</p>
  
  <pre><code>array
    'paginationPage' =&gt; int 2
    'id' =&gt; int 30
    'searchKey' =&gt; string 'test' (length=4)
  </code></pre>
  
  <p>Because $summary, $title and $authors are not present, they will get their default value which is <code>null</code>. When assigning a null value to an argument, it will be skipped which results in a $parameters array that looks like this:</p>
  
  <pre><code>array
    'searchKey' =&gt; string 'test' (length=4)
    'paginationPage' =&gt; int 2
  </code></pre>
  
  <p>Which result in a method call like:</p>
  
  <pre><code>public function search('test', 2, null, null, 0) { 
          ... 
  }
  </code></pre>
  
  <p>While it should be:</p>
  
  <pre><code>public function search('test', null, null, null, 2) { 
          ... 
  }
  </code></pre>
  
  <p>Hopefully you see the problem. How can I make sure those null values are also put into my <code>$parameters</code> array. Adding an invalid value is not possible, because it is user input, so that can be basically everything.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>In the example above the method <code>search</code> is hardcoded. But one of the simplified things is that <code>search</code> is actually a variable and because of that <code>search</code> can be anything. This means that I don't know what the parameters of the method are and I can't predefine them before the foreach loop. The solution of predefining the parameters is actually exactly what this code should be doing.</p>