empty() does not work on classes that extend ArrayObject
| 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
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:
- isset() and empty() don't invoke ArrayObject::offsetGet() (php-src/621)
- isset() and empty() don't invoke ArrayObject::offsetGet() (php-src/614)
History
AllCommentsChangesGit/SVN commits
[2014-03-25 10:45 UTC] datibbaw@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: datibbaw
[2014-03-25 10:49 UTC] narf at devilix dot net