|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66834 empty() does not work on classes that extend ArrayObject
Submitted: 2014-03-06 13:37 UTC Modified: 2014-03-25 10:45 UTC
From: thomas at weinert dot info Assigned: datibbaw (profile)
Status: Closed Package: SPL related
PHP Version: 5.6.0alpha2 OS:
Private report: No CVE-ID: None
 [2014-03-06 13:37 UTC] thomas at weinert dot info
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:

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' => ''));

Expected result:
string(38) "Called: ArrayObjectChild::offsetExists" 
string(35) "Called: ArrayObjectChild::offsetGet" 

Actual result:
string(38) "Called: ArrayObjectChild::offsetExists" 


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-25 10:45 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: datibbaw
 [2014-03-25 10:45 UTC]
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

 For Windows:
Thank you for the report, and for helping us make PHP better.

 [2014-03-25 10:49 UTC] narf at devilix dot net
FYI, issues #43650, #52655, #60577 look quite similar to this one.
 [2014-05-08 17:11 UTC]
Bug 67067 is also a duplicate of this one.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 23:01:30 2024 UTC