All the assumption I want to remember in PHP

Probably linked to some alcohol I drank to young, I always forget some key assumption in PHP.

NULL is NULL
NULL is EMPTY
NULL is FALSE
NULL has a sizeof 0

BUT

FALSE is not NULL
FALSE is EMPTY
FALSE is FALSE
FALSE has a sizeof 1

AND

empty ARRAY is not NULL
empty ARRAY is EMPTY
empty ARRAY is FALSE
empty ARRAY has a sizeof 0

$test=NULL;
if(is_null($test)){print("NULL is NULL");}else{print("NULL is not NULL");}
// NULL is NULL
if(empty($test)){print("NULL is EMPTY");}else{print("NULL is not EMPTY");}
// NULL is empty
if($test){print("NULL is TRUE");}else{print("NULL is FALSE");}
// NULL is FALSE
print(count($test));
// 0
$test=false;
if(is_null($test)){print("FALSE is NULL");}else{print("FALSE is not NULL");}
// FALSE is not NULL
if(empty($test)){print("FALSE is EMPTY");}else{print("FALSE is not EMPTY");}
// FALSE is EMPTY
if($test){print("FALSE is TRUE");}else{print("FALSE is FALSE");}
// FALSE is FALSE
print(count($test));
// 1
$test=array();
if(is_null($test)){print("empty ARRAY is NULL");}else{print("empty ARRAY is not NULL");}
// empty ARRAY is not NULL
if(empty($test)){print("empty ARRAY is EMPTY");}else{print("empty ARRAY is not EMPTY");}
// empty ARRAY is EMPTY
if($test){print("empty ARRAY is TRUE");}else{print("empty ARRAY is FALSE");}
// empty ARRAY is FALSE

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*