Bug #66834 [Com]: empty() does not work on classes that extend ArrayObject

From: Date: Thu, 08 May 2014 17:11:31 +0000
Subject: Bug #66834 [Com]: empty() does not work on classes that extend ArrayObject
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185723@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 Comment by: levim@php.net Reported by: thomas at weinert dot info Summary: empty() does not work on classes that extend ArrayObject Status: Closed Type: Bug Package: SPL related PHP Version: 5.6.0alpha2 Assigned To: datibbaw Block user comment: N Private report: N New Comment: Bug 67067 is also a duplicate of this one. Previous Comments: ------------------------------------------------------------------------ [2014-05-08 17:11:07] levim@php.net Related To: Bug #67067 ------------------------------------------------------------------------ [2014-03-25 10:49:29] narf at devilix dot net FYI, issues #43650, #52655, #60577 look quite similar to this one. ------------------------------------------------------------------------ [2014-03-25 10:45:07] 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-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

« previous php.bugs (#185723) next »