title: Default value if variable not sets
body: <p>I sometimes have variables that might not be set and I would like to use a default parameter instead. Like here:</p>
  
  <pre><code>if ($p == "a") doSomething();
  </code></pre>
  
  <p>If <code>$p</code> is not defined PHP throws <code>Notice: Undefined variable</code>. To avoid this I often I used this construct in such a case:</p>
  
  <pre><code>$p = (isset($p) ? $p : "");
  </code></pre>
  
  <p>But that is ugly if you have to use it a lot. So I wrote a function for it:</p>
  
  <pre><code>function getIfSet(&amp;$value, $default = '')
  {
      return isset($value) ? $value : $default;
  }
  
  // Example
  if (getIfSet($p) == "a") doSomething();
  </code></pre>
  
  <p>I wonder if there is a PHP function for this or how you solve this.</p>