note 116176 deleted from language.types.null by salathe

From: Date: Fri, 21 Nov 2014 14:53:12 +0000
Subject: note 116176 deleted from language.types.null by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-200978@lists.php.net to get a copy of this message
Note Submitter: naitsabes dot pawlak at gmail dot com ---- Why "" == NULL array() == NULL gives TRUE? '==' is comparison operator which gives true if both sides are equal after type juggling. Lets look first at "" == NULL When you are comparing NULL with string, then NULL is converted to empty string "". So operator '==' is comparing strings in this situation: "" == NULL is converted to: "" == "" which gives TRUE. When you are comparing NULL with anything else except strings, then both sides are converted to bool. So when you are comparing null with empty array, then null is converted to FALSE and empty array is converted to FALSE. array() == NULL is converted to FALSE == FALSE which gives of course TRUE. I'm basing on http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.types My previous answer was wrong about comparing "" == NULL. I was assuming that here both sides are also converted to bool, but it isn't true - NULL is converted here to string. You can just check comparison: "0" == NULL if in this comparison both sides are converted to bool then it should give TRUE ((bool)NULL = FALSE, (bool)"0" = FALSE). But this comparison gives FALSE.

« previous php.notes (#200978) next »