ID:               44899
 Updated by:       [EMAIL PROTECTED]
 Reported By:      nuttzy at spellingcow dot com
 Status:           Closed
 Bug Type:         Scripting Engine problem
 Operating System: CentOS
 PHP Version:      5.2.6
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Reclassified...

The source has been fixed, not the documentation.


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

[2008-05-03 00:41:58] [EMAIL PROTECTED]

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.

Fixed in 5_3 and HEAD. (patch by Etienne Kneuss)

------------------------------------------------------------------------

[2008-05-02 20:53:35] nuttzy at spellingcow dot com

Description:
------------
Per http://bugs.php.net/bug.php?id=40797, the behavior of empty() was
modified to call the __isset magic method.  There is at least one case
where this changes the behavior of empty() to falsely report "not empty"
when in fact the desired result is "empty".

I suppose you would need an __empty() magic method, but that sounds
heinous.  Overloading docs should at least be updated to warn the
developer.

Reproduce code:
---------------
<?
class myclass
{
    private $_raw_data = array() ;

    function __construct( $data)
    {
        $this->_raw_data = $data ;
    }

    function __isset( $field_name)
    {
        return isset($this->_raw_data[$field_name]);
    }    
}

$_POST['foo']='' ;
$myclass = new myclass( $_POST) ;

// correct reports "isset"
echo (isset($myclass->foo)) ? 'isset' : 'not isset') ;

// incorrectly reports "not empty"
echo (empty($myclass->foo)) ? 'empty' : 'not empty' ;

// a way to get around the broken empty() call
echo ($myclass->foo) ? 'not empty' : 'empty' ;

?>

Expected result:
----------------
isset
empty
empty

Actual result:
--------------
isset
not empty
empty


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44899&edit=1

Reply via email to