Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I run the following:</p> <pre><code>echo '&lt;?php echo $foo; ?&gt;' | php </code></pre> <p>I get an error:</p> <pre><code>PHP Notice: Undefined variable: foo in /home/altern8/- on line 1 </code></pre> <p>If I run the following:</p> <pre><code>echo '&lt;?php if ( isset($foo) ) { echo $foo; } ?&gt;' | php </code></pre> <p>I do not get the error. </p> <p>If I have a variable that should be set, I usually do something like the following.</p> <pre><code>$foo = isset($foo) ? $foo : null; </code></pre> <p>or</p> <pre><code>if ( ! isset($foo) ) $foo = null; </code></pre> <p>That way, later in the script, I can safely use $foo and know that it "is set", and that it defaults to null. Later I can <code>if ( is_null($foo) ) { /* ... */ }</code> if I need to and know for certain that the variable exists, even if it is null.</p> <p>The full <a href="http://php.net/manual/en/function.isset.php" rel="nofollow noreferrer">isset documentation</a> reads a little more than just what was initially pasted. Yes, it returns false for a variable that was previously set but is now null, but it also returns false if a variable has not yet been set (ever) and for any variable that has been marked as unset. It also notes that the NULL byte ("\0") is not considered null and will return true.</p> <blockquote> <p>Determine whether a variable is set.</p> <p>If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload