ID:               45518
 User updated by:  stephen dot cuppett at sas dot com
 Reported By:      stephen dot cuppett at sas dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Variables related
 Operating System: Windows XP/2003
 PHP Version:      5.2.6
 New Comment:

NM, I see the loose comparisons table in the appendix.


Previous Comments:
------------------------------------------------------------------------

[2008-07-15 12:19:28] stephen dot cuppett at sas dot com

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 this bug report at http://bugs.php.net/?id=45518&edit=1

Reply via email to