Skip to content

Instantly share code, notes, and snippets.

@kanonji
Created September 24, 2010 18:28
Show Gist options
  • Save kanonji/595798 to your computer and use it in GitHub Desktop.
Save kanonji/595798 to your computer and use it in GitHub Desktop.
<h1>Look see when Undefined variable/offset notice occurs with isset() is_null() empty() if()</h1>
<h2>$foo;</h2>
<?php $foo;?>
<h3>isset($foo)</h3>
<p>
<?php var_dump(isset($foo)); ?>
</p>
<h3>is_null($foo)</h3>
<p>
<?php var_dump(is_null($foo)); ?>
</p>
<h3>empty($foo)</h3>
<p>
<?php var_dump(empty($foo)); ?>
</p>
<h3>($foo)</h3>
<p>
<?php var_dump(($foo)); ?>
</p>
<h2>$bar = array();</h2>
<?php $bar = array(); ?>
<h3>isset($bar[0])</h3>
<p>
<?php var_dump(isset($bar[0])); ?>
</p>
<h3>is_null($bar[0])</h3>
<p>
<?php var_dump(is_null($bar[0])); ?>
</p>
<h3>empty($bar[0])</h3>
<p>
<?php var_dump(empty($bar[0])); ?>
</p>
<h3>($bar[0])</h3>
<p>
<?php var_dump(($bar[0])); ?>
</p>
<h2>$bar = array();</h2>
<h3>isset($bar['foo'])</h3>
<p>
<?php var_dump(isset($bar['foo'])); ?>
</p>
<h3>is_null($bar['foo'])</h3>
<p>
<?php var_dump(is_null($bar['foo'])); ?>
</p>
<h3>empty($bar['foo'])</h3>
<p>
<?php var_dump(empty($bar['foo'])); ?>
</p>
<h3>($bar['foo'])</h3>
<p>
<?php var_dump(($bar['foo'])); ?>
</p>
<h2>$bar['bar'] = 'bar';</h2>
<?php $bar['bar'] = 'bar'; ?>
<h3>isset($bar[0])</h3>
<p>
<?php var_dump(isset($bar[0])); ?>
</p>
<h3>is_null($bar[0])</h3>
<p>
<?php var_dump(is_null($bar[0])); ?>
</p>
<h3>empty($bar[0])</h3>
<p>
<?php var_dump(empty($bar[0])); ?>
</p>
<h3>($bar[0])</h3>
<p>
<?php var_dump(($bar[0])); ?>
</p>
<h2>$bar['bar'] = 'bar';</h2>
<h3>isset($bar['foo'])</h3>
<p>
<?php var_dump(isset($bar['foo'])); ?>
</p>
<h3>is_null($bar['foo'])</h3>
<p>
<?php var_dump(is_null($bar['foo'])); ?>
</p>
<h3>empty($bar['foo'])</h3>
<p>
<?php var_dump(empty($bar['foo'])); ?>
</p>
<h3>($bar['foo'])</h3>
<p>
<?php var_dump(($bar['foo'])); ?>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment