]> granicus.if.org Git - php/commitdiff
Fixed bug #34934 (offsetExists is not called from array_key_exists)
authorDmitry Stogov <dmitry@php.net>
Fri, 21 Oct 2005 15:20:30 +0000 (15:20 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 21 Oct 2005 15:20:30 +0000 (15:20 +0000)
ext/standard/array.c
ext/standard/tests/array/bug34934.phpt [new file with mode: 0755]

index a5ec285b85127000f99002f181049b13ea309552..927ffcc1f61d47990c3fa687a349942f97dd731c 100644 (file)
@@ -4658,6 +4658,17 @@ PHP_FUNCTION(array_key_exists)
                RETURN_FALSE;
        }
 
+       if (Z_TYPE_PP(array) == IS_OBJECT &&
+           Z_OBJ_HT_PP(array)->has_dimension &&
+           (Z_OBJ_HT_PP(array)->has_dimension != std_object_handlers.has_dimension ||
+            instanceof_function_ex(Z_OBJCE_PP(array), U_CLASS_ENTRY(zend_ce_arrayaccess), 1 TSRMLS_CC))) {
+         if (Z_OBJ_HT_PP(array)->has_dimension(*array, *key, 0 TSRMLS_CC)) {
+               RETURN_TRUE;
+         } else {
+               RETURN_FALSE;
+         }
+       }
+
        switch (Z_TYPE_PP(key)) {
                case IS_STRING:
                case IS_UNICODE:
diff --git a/ext/standard/tests/array/bug34934.phpt b/ext/standard/tests/array/bug34934.phpt
new file mode 100755 (executable)
index 0000000..1f5d161
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #34934 (offsetExists is not called from array_key_exists)
+--FILE--
+<?php
+class MyArray extends ArrayObject {
+  function offsetExists($mKey) { 
+       echo __METHOD__ . "($mKey)\n";
+       return true;
+  }
+}
+
+$a = new MyArray();
+
+var_dump(array_key_exists("test", $a));
+?>
+--EXPECT--
+MyArray::offsetExists(test)
+bool(true)