php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40036 empty() does not work correctly with ArrayObject when using ARRAY_AS_PROPS
Submitted: 2007-01-05 18:33 UTC Modified: 2007-01-07 03:52 UTC
From: matthew at zend dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 5.2.0 OS: Debian GNU/Linux (unstable)
Private report: No CVE-ID:
 [2007-01-05 18:33 UTC] matthew at zend dot com
Description:
------------
When using the ArrayObject::ARRAY_AS_PROPS flag with ArrayObject, empty() does not work correctly on properties defined using either array notation or object notation (and not previously declared in the object). null, false, and empty strings do not return a true value from empty().

If ARRAY_AS_PROPS is not specified, empty() works fine.

Reproduce code:
---------------
class View extends ArrayObject
{
    public function __construct(array $array = array())
    {
        parent::__construct($array, ArrayObject::ARRAY_AS_PROPS);
    }
}

$view = new View();
$view->foo = false;
$view->bar = null;
$view->baz = '';
if (empty($view['foo']) || empty($view->foo)) {
    echo "View::foo empty\n";
}
if (empty($view['bar']) || empty($view->bar)) {
    echo "View::bar empty\n";
}
if (empty($view['baz']) || empty($view->baz)) {
    echo "View::baz empty\n";
}

Expected result:
----------------
View::foo empty
View::bar empty
View::baz empty

Actual result:
--------------
No output received.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-07 03:52 UTC] iliaa@php.net
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.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 06:02:13 2014 UTC