From:             tschundler at gmail dot com
Operating system: FreeBSD 6.0
PHP version:      5.0.5
PHP Bug Type:     Arrays related
Bug description:  array_key_exists and isset misbehavior with ArrayAccess

Description:
------------
Functions to test an array's content don't work consistently with
ArrayAccess objects.

In the example, the object will return TRUE a request for any key. But,
array_key_exists always returns FALSE, seemingly testing nothing, when it
should be using the offsetExists method.

Additionally, isset() on an array will return FALSE if the value at that
offset is NULL. But with an ArrayAccess object, it returns TRUE, using the
offsetExists method.

Reproduce code:
---------------
class ArrayTest implements ArrayAccess {
    function offsetExists ($offset) {return TRUE;}
    function offsetGet ($offset) {return ($offset==0) ? NULL : $offset;}
    function offsetSet ($offset, $value) {}
    function offsetUnset ($offset) {}
}

echo "with ArrayAcces:\n";
$x=new ArrayTest();
var_dump(array_key_exists(0,$x));
var_dump(array_key_exists(1,$x));
var_dump(isset($x[0]));
var_dump(isset($x[1]));

echo "with array():\n";
$y=array(0=>NULL,1=>1);
var_dump(array_key_exists(0,$y));
var_dump(array_key_exists(1,$y));                         
var_dump(isset($y[0]));
var_dump(isset($y[1]));


Expected result:
----------------
with ArrayAcces:
bool(true)
bool(true)
bool(false)
bool(true)
with array():
bool(true)
bool(true)
bool(false)
bool(true)


Actual result:
--------------
with ArrayAcces:
bool(false)
bool(false)
bool(true)
bool(true)
with array():
bool(true)
bool(true)
bool(false)
bool(true)


-- 
Edit bug report at http://bugs.php.net/?id=34849&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34849&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34849&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34849&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34849&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34849&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34849&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34849&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34849&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34849&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34849&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34849&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34849&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34849&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34849&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34849&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34849&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34849&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34849&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34849&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34849&r=mysqlcfg

Reply via email to