Detecting insufficient PHP variables: FALSE vs NULL vs unset() vs empty()?
<p>What is the best way to define that a value does not exist in PHP, or is not sufficent for the applications needs. </p>

<p><code>$var = NULL</code>, <code>$var = array()</code>, <code>$var = FALSE</code>?</p>

<p>And what is the best way to test?</p>

<p><code>isset($var)</code>, <code>empty($var)</code>, <code>if($var != NULL)</code>, <code>if($var)</code>?</p>

<p>Initializing variables as what they will be, e.g. <code>NULL</code> if a string, <code>array()</code> if they will be arrays, has some benefits in that they will function in the setting they are ment to without any unexpected results. </p>

<p>e.g. <code>foreach($emptyArray)</code> won't complain it just wont output anything, whereas <code>foreach($false)</code> will complain about the wrong variable type.</p>

<p>But it seams like an unnecessary hassle to have so many different ways of doing basically the same thing. eg. <code>if(empty($var))</code> or <code>if ($var == NULL)</code></p>

<p><hr/>
<strong>Duplicate:</strong> <a href="http://stackoverflow.com/questions/418066">Best way to test for a variable’s existence in PHP; isset() is clearly broken</a></p>
