From: stephen dot cuppett at sas dot com Operating system: Windows XP/2003 PHP version: 5.2.6 PHP Bug Type: Variables related Bug description: NULL matching zero, empty array, false
Description: ------------ I noticed a behavior with PHP 5.2.x that I found disturbing. PHP is matching variables initialized to zero, an empty array and false with NULL. From the documentation here: http://us2.php.net/NULL The only thing that should match NULL are ones that meet these criteria: A variable is considered to be null if: - it has been assigned the constant NULL. - it has not been set to any value yet. - it has been unset(). The function empty() should return true in the above cases (and does), but a comparison operator of == should not. FYI, is_null() returns false and the === operator works as expected too. Reproduce code: --------------- <?php $empty_array = array(); if ($empty_array == NULL) echo "Empty array, same as NULL\n"; else echo "Empty array, diff from NULL\n"; $zero = 0; if ($zero == NULL) echo "Zero, same as NULL\n"; else echo "Zero, different from NULL\n"; ?> Expected result: ---------------- Empty array, diff from NULL Zero, different from NULL Actual result: -------------- Empty array, same as NULL Zero, same as NULL -- Edit bug report at http://bugs.php.net/?id=45518&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45518&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45518&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45518&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45518&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45518&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45518&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45518&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45518&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45518&r=support Expected behavior: http://bugs.php.net/fix.php?id=45518&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45518&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45518&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45518&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45518&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45518&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45518&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45518&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45518&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45518&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45518&r=mysqlcfg