Tag Archives: issues

php is NULL

I’ve some codes like:

// do something...

$json = json_decode($data);
if ($json == NULL) {
    $json = array("message" => "data null");
}
// do some out print
// ....

But, i hadn’t got the empty json result with message “data null” when $data is empty array();

After some google searches. references to http://php.net/manual/en/language.types.null.php

Note: empty array is converted to null by non-strict equal ‘==’ comparison. Use is_null() or ‘===’ if there is possible of getting empty array.

$a = array();
$a == null  <== return true
$a === null <== return false
is_null($a) <== return false