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: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matthew at zend dot com
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 14:01:29 2024 UTC