php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch array_key_exists_patch.txt for Arrays related Bug #60039

Patch version 2011-10-11 12:19 UTC

Return to Bug #60039 | Download this patch
Patch Revisions:

Developer: nikic@php.net

Index: ext/standard/array.c
===================================================================
--- ext/standard/array.c	(revision 318013)
+++ ext/standard/array.c	(working copy)
@@ -4374,24 +4374,34 @@
 	}
 
 	switch (Z_TYPE_P(key)) {
-		case IS_STRING:
-			if (zend_symtable_exists(array, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1)) {
+		case IS_DOUBLE:
+			if (zend_hash_index_exists(array, zend_dval_to_lval(Z_DVAL_P(key)))) {
 				RETURN_TRUE;
 			}
 			RETURN_FALSE;
+
+		case IS_RESOURCE:
+		case IS_BOOL:
 		case IS_LONG:
 			if (zend_hash_index_exists(array, Z_LVAL_P(key))) {
 				RETURN_TRUE;
 			}
 			RETURN_FALSE;
+
+		case IS_STRING:
+			if (zend_symtable_exists(array, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1)) {
+				RETURN_TRUE;
+			}
+			RETURN_FALSE;
+		
 		case IS_NULL:
-			if (zend_hash_exists(array, "", 1)) {
+			if (zend_hash_exists(array, "", sizeof(""))) {
 				RETURN_TRUE;
 			}
 			RETURN_FALSE;
 
 		default:
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be either a string or an integer");
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "The key must be a scalar");
 			RETURN_FALSE;
 	}
 }
Index: ext/standard/tests/array/array_key_exists_variation1.phpt
===================================================================
--- ext/standard/tests/array/array_key_exists_variation1.phpt	(revision 318013)
+++ ext/standard/tests/array/array_key_exists_variation1.phpt	(working copy)
@@ -115,30 +115,20 @@
 bool(false)
 
 -- Iteration 5 --
-
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
 bool(false)
 
 -- Iteration 6 --
-
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
 bool(false)
 
 -- Iteration 7 --
-
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
 bool(false)
 
 -- Iteration 8 --
+bool(true)
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
-
 -- Iteration 9 --
+bool(true)
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
-
 -- Iteration 10 --
 bool(false)
 
@@ -146,25 +136,17 @@
 bool(false)
 
 -- Iteration 12 --
+bool(true)
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
-
 -- Iteration 13 --
+bool(true)
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
-
 -- Iteration 14 --
+bool(true)
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
-
 -- Iteration 15 --
+bool(true)
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
-
 -- Iteration 16 --
 bool(false)
 
@@ -173,7 +155,7 @@
 
 -- Iteration 18 --
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
+Warning: array_key_exists(): The key must be a scalar in %s on line %d
 bool(false)
 
 -- Iteration 19 --
@@ -187,7 +169,7 @@
 
 -- Iteration 22 --
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
+Warning: array_key_exists(): The key must be a scalar in %s on line %d
 bool(false)
 
 -- Iteration 23 --
@@ -197,7 +179,5 @@
 bool(false)
 
 -- Iteration 25 --
-
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
 bool(false)
-Done
\ No newline at end of file
+Done
Index: ext/standard/tests/array/array_key_exists_variation3.phpt
===================================================================
--- ext/standard/tests/array/array_key_exists_variation3.phpt	(revision 318013)
+++ ext/standard/tests/array/array_key_exists_variation3.phpt	(working copy)
@@ -19,9 +19,8 @@
 
 $search = array ('zero', 'one', 'two');
 
-$iterator = 1;
-foreach($keys as $key) {
-	echo "\n-- Iteration $iterator --\n";
+foreach($keys as $i => $key) {
+	echo "\n-- Iteration $i --\n";
 	echo "Pass float as \$key:\n";
 	var_dump(array_key_exists($key, $search));
 	echo "Cast float to int:\n";
@@ -34,27 +33,21 @@
 --EXPECTF--
 *** Testing array_key_exists() : usage variations ***
 
--- Iteration 1 --
+-- Iteration 0 --
 Pass float as $key:
-
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
+bool(true)
 Cast float to int:
 bool(true)
 
 -- Iteration 1 --
 Pass float as $key:
-
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
+bool(true)
 Cast float to int:
 bool(true)
 
--- Iteration 1 --
+-- Iteration 2 --
 Pass float as $key:
-
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
+bool(true)
 Cast float to int:
 bool(true)
-Done
\ No newline at end of file
+Done
Index: ext/standard/tests/array/array_key_exists.phpt
===================================================================
--- ext/standard/tests/array/array_key_exists.phpt	(revision 318013)
+++ ext/standard/tests/array/array_key_exists.phpt	(working copy)
@@ -87,8 +87,6 @@
 var_dump( array_key_exists(false, 17.5) ); 
 // args more than expected 
 var_dump( array_key_exists(1, array(), array()) ); 
-// first argument as floating point value
-var_dump( array_key_exists(17.5, array(1,23) ) ) ; 
 
 echo "\n*** Testing operation on objects ***\n";
 class key_check
@@ -114,7 +112,7 @@
 var_dump(array_key_exists("arr", $key_check_obj)); //found, public member
 var_dump(array_key_exists("var", $key_check_obj->arr)); //found,  key is in member array
 
-/* error condition, first arguemnt as object */
+/* error condition, first argument as object */
 var_dump( array_key_exists($key_check_obj, $key_check_obj) );
 echo "Done\n";
 ?>
@@ -252,7 +250,7 @@
 Warning: array_key_exists() expects exactly 2 parameters, 0 given in %s on line %d
 NULL
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
+Warning: array_key_exists(): The key must be a scalar in %s on line %d
 bool(false)
 
 Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d
@@ -276,9 +274,6 @@
 Warning: array_key_exists() expects exactly 2 parameters, 3 given in %s on line %d
 NULL
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
-bool(false)
-
 *** Testing operation on objects ***
 bool(false)
 bool(false)
@@ -287,6 +282,6 @@
 bool(true)
 bool(true)
 
-Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
+Warning: array_key_exists(): The key must be a scalar in %s on line %d
 bool(false)
 Done
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC