title: Passing a null DateTime to php function
body: <p>I have a function in php that I want to accept either a DateTime object or null. E.g.</p>
  
  <pre><code>function foo(DateTime $aDate){
     if ($aDate == null){
         echo "You passed a null variable";
     } else {
         echo "You passed the date " . $aDate-&gt;format('Y-m-d');
     }
  }
  </code></pre>
  
  <p>Trouble is, because the function expects a DateTime object it flips out when I pass null to it and gives an error:</p>
  
  <pre><code>Catchable fatal error: Argument 1 passed to foo() must be an instance of DateTime, null given,...
  </code></pre>
  
  <p>How can I pass null to the function and avoid this error?</p>