"Zen" or "The Four Kinds of Nothing"

Some things in PHP are so weird that it’s best to write them down once, so you can marvel at them in peace.

For example, if a variable $a is set to the value null in PHP, isset($a) still returns false. (This is nothing new, but it is remarkable in the truest sense of the word.) Also interesting is the behavior of empty and is_null for unset variables and variables with the value null. To demonstrate, we initialize variable $a with the value null and leave variable $b completely uninitialized:

$a = null;
# $b is not initialized

Here are the tests:

Test $a $b
isset() false false
empty() true true
is_null() true true
=== null true true

The result of isset($a) defies all intuition.

Things get truly bizarre with the doubled (?) notice PHP Notice: Undefined variable: b in /home/aljoscha/test.php on line 10 Notice: Undefined variable: b in /home/aljoscha/test.php on line 10, triggered by is_null($b) or ($b === null), and the surprising result: true!