Bug #66834 [Opn->Csd]: empty() does not work on classes that extend ArrayObject
| From: | datibbaw@php.net | Date: | Tue, 25 Mar 2014 10:45:07 +0000 |
| Subject: | Bug #66834 [Opn->Csd]: empty() does not work on classes that extend ArrayObject | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184877@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66834&edit=1
ID: 66834
Updated by: datibbaw@php.net
Reported by: thomas at weinert dot info
Summary: empty() does not work on classes that extend
ArrayObject
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
PHP Version: 5.6.0alpha2
-Assigned To:
+Assigned To: datibbaw
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
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/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2014-03-06 13:37:18] thomas at weinert dot info
Description:
------------
Given that $object['foo'] is an empty string, empty($object['foo']) returns
FALSE, if $object is an instance of a class that extends ArrayObject. It returns TRUE on an instance
of ArrayObject or an implementation of ArrayAccess.
It never calls offsetGet() on the extended ArrayObject.
Test script:
---------------
<?php
class ArrayObjectChild extends ArrayObject {
public function offsetExists($offset) {
var_dump('Called: '.__METHOD__);
return parent::offsetExists($offset);
}
public function offsetGet($offset) {
var_dump('Called: '.__METHOD__);
return parent::offsetGet($offset);
}
}
$object = new ArrayObjectChild(array('foo' => ''));
var_dump(empty($object['foo']));
Expected result:
----------------
string(38) "Called: ArrayObjectChild::offsetExists"
string(35) "Called: ArrayObjectChild::offsetGet"
bool(true)
Actual result:
--------------
string(38) "Called: ArrayObjectChild::offsetExists"
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66834&edit=1