is_null()

The manual says is_null returns a TRUE/FALSE.

http://php.net/manual/en/function.is-null.php

Why does this return a 1? I expected “TRUE”.


$_SESSION['logged_on'] = null;

if (is_null($_SESSION['logged_on'])) {
  echo is_null($_SESSION['logged_on']) . '<br/>';
}
exit;

When you echo a boolean, it is implicitly typecast to a string, and PHP decided that true would convert to “1” and false to “”.

Thanks Jeff Mott.

$b=false;

var_dump($b);

// boolean false

Use var_dump() to test expectations - shows value and type.

@nichemtktg

Maybe this will help:

http://deformedweb.co.uk/php_variable_tests.php

Thanks Cups and John_Betong