]> 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:19:40 +0000 (15:19 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 21 Oct 2005 15:19:40 +0000 (15:19 +0000)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug34934.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 5907a6d68f82a620c387619411ecfff352492ed1..885d442c7b737ab4c0a687b4861378b46eabeeac 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Oct 2005, PHP 5.1 Release Candidate 4
 - Fixed fgetcsv() and fputcsv() inconsistency. (Dmitry)
+- Fixed bug #34934 (offsetExists is not called from array_key_exists). (Dmitry)
 - Fixed bug #34905 (Digest authentication does not work with Apache 1). (Ilia)
 - Fixed bug #34902 (mysqli::character_set_name() - undefined method). (Tony)
 - Fixed bug #34893 (PHP5.1 overloading, Cannot access private property).
index fd9f2af36facbadce2e06daf9377f5afd615e725..40372e99b6a1f904ddba21be589342251cec04b1 100644 (file)
@@ -4390,6 +4390,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), 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:
                        if (zend_symtable_exists(HASH_OF(*array), Z_STRVAL_PP(key), Z_STRLEN_PP(key)+1)) {
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)