#36786 [Opn->Bgs]: empty() on an element of ArrayObject

From: Date: Sun, 19 Mar 2006 13:54:59 +0000
Subject: #36786 [Opn->Bgs]: empty() on an element of ArrayObject
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-94557@lists.php.net to get a copy of this message
ID: 36786 Updated by: helly@php.net Reported By: davd dot nqd at gmail dot com -Status: Open +Status: Bogus Bug Type: SPL related -Operating System: Windows XP +Operating System: * -PHP Version: 5.1.2 +PHP Version: 5.* -Assigned To: +Assigned To: helly New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Actually the problem is that interface ArrayAccess was not designed to support this. In fact it was designed to only check for existance (neither isset nor empty). Eventually we could change the interface in PHP 6 or invent some workaround for SPL's ArrayObject/ArrayIterator later. In case you always need empty you can overwrite offsetExists. Previous Comments: ------------------------------------------------------------------------ [2006-03-19 11:40:14] davd dot nqd at gmail dot com Oops, I made a typo. Instead of ".. returns true", I meant "... returns false". ------------------------------------------------------------------------ [2006-03-19 11:37:29] davd dot nqd at gmail dot com Description: ------------ When applying empty() to an element of an ArrayObject which is the empty string, empty() returns true. But, the manual for empty() states that "an empty string" is considered empty. Note: I tried to reproduce this bug using a custom implementation of ArrayAccess which worked as expected. Reproduce code: --------------- <?php $array = array('index' => ''); $arrayObject = new ArrayObject($array); if (empty($arrayObject['index'])) { echo 'empty'; } else { echo 'not empty'; } ?> Expected result: ---------------- empty Actual result: -------------- not empty ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36786&edit=1

« previous php.bugs (#94557) next »