title: php function get default value if null is passed
body: <p>I'm currently passing a value - which might be null - to a function that has a default value for that parameter. I expected that if the parameter is null, it would return the default value. But that does not seem to be the case.
  Now I was wondering if there is a way to work around this?</p>
  <p>I know I can check if the value is null, and don't pass it when it is, but I don't want to have too many if's in my code. I just want a clean way to grab the default value if it's null.</p>
  <p><strong>Some extra info</strong>: I'm using Laravel framework 8 - maybe some nice functions in Laravel I don't know yet.</p>
  <p>Example <a href="http://sandbox.onlinephpfunctions.com/code/771e9d4d446dcc07c5cb224e7778d5c19ff365e5" rel="nofollow noreferrer">code</a>:</p>
  <pre><code>&lt;?php
  
  class Person {
      private $name;
      
      public function greet(string $greeting = 'Hello')
      {
          return sprintf('%s %s', $greeting, $this-&gt;name);
      }
      
      public function setName($name)
      {
          $this-&gt;name = $name;
          return $this;
      }
  }
  
  $externalInput = null;
  
  $person = (new Person())-&gt;setName('Maik');
  echo $person-&gt;greet($externalInput);
  </code></pre>
  <p>This is just an example code, so don't mind the security issues this might have. That's all taken care off in my real code. This code is just to illustrate the problem I'm having.</p>