|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2005-10-13 08:24 UTC] helly@php.net
  [2011-07-11 14:17 UTC] jon at phpsitesolutions dot com
  [2011-07-11 14:20 UTC] jon at phpsitesolutions dot com
  [2011-07-12 09:11 UTC] arpad@php.net
  [2015-02-23 08:51 UTC] thomas at gielfeldt dot dk
  [2015-02-23 10:26 UTC] yohgaki@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 14:00:01 2025 UTC | 
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)