php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thomas at weinert dot info
New email:
PHP Version: OS:

 

 [2014-03-06 13:37 UTC] 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)

Patches

Pull Requests

Pull requests:

History

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


 [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] levim@php.net
Bug 67067 is also a duplicate of this one.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC