cvs: php4 / TODO /ext/standard/ array.c

[email protected] ("Andrei Zmievski") Thu, 01 Jun 2000 13:52:09 -0000
Newsgroups php.version4
Message-ID <cvsandrei959867529@cvsserver>
andrei		Thu Jun  1 06:52:09 2000 EDT

  Modified files:
    /php4	TODO 
    /php4/ext/standard	array.c 
  Log:
  
  @- Added third argument to in_array(). If it's true, then in_array()
  @  will use strict comparison instead of the default one. (Andrei)
  
  Fixes bug #4753
  
  
Index: php4/TODO
diff -u php4/TODO:1.84 php4/TODO:1.85
--- php4/TODO:1.84	Wed May 31 02:25:51 2000
+++ php4/TODO	Thu Jun  1 06:52:08 2000
@@ -10,7 +10,7 @@
 global
 ------
     * sort ini entries so that phpinfo() show them in some nice order.
-    * make everything on the language-level independent of your locate setings.
+    * make everything on the language-level independent of your locale setings.
     * allow methods to be called as callbacks. eg: array_walk($myarray,"this->print()");
     * always build the standalone executable as well as the chosen SAPI 
       target.
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.47 php4/ext/standard/array.c:1.48
--- php4/ext/standard/array.c:1.47	Tue May 30 10:03:56 2000
+++ php4/ext/standard/array.c	Thu Jun  1 06:52:08 2000
@@ -1027,18 +1027,20 @@
 }
 /* }}} */
 
-/* {{{ proto bool in_array(mixed needle, array haystack)
+/* {{{ proto bool in_array(mixed needle, array haystack [, bool strict])
    Checks if the given value exists in the array */
 PHP_FUNCTION(in_array)
 {
 	zval **value,				/* value to check for */
 		 **array,				/* array to check in */
-		 **entry_ptr,			/* pointer to array entry */
-		 *entry,				/* actual array entry */
+		 **strict,				/* strict comparison or not */
+		 **entry,				/* pointer to array entry */
 		  res;					/* comparison result */
 	HashTable *target_hash;		/* array hashtable */
+	int (*compare_func)(zval *, zval *, zval *) = is_equal_function;
 
-	if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &value, &array) == FAILURE) {
+	if (ARG_COUNT(ht) < 2 || ARG_COUNT(ht) > 3 ||
+		zend_get_parameters_ex(ARG_COUNT(ht), &value, &array, &strict) == FAILURE) {
 		WRONG_PARAM_COUNT;
 	}
 	
@@ -1052,12 +1054,17 @@
 		RETURN_FALSE;
 	}
 
+	if (ARG_COUNT(ht) == 3) {
+		convert_to_boolean_ex(strict);
+		if (Z_LVAL_PP(strict) == 1)
+			compare_func = is_identical_function;
+	}
+
 	target_hash = HASH_OF(*array);
 	zend_hash_internal_pointer_reset(target_hash);
-	while(zend_hash_get_current_data(target_hash, (void **)&entry_ptr) == SUCCESS) {
-		entry = *entry_ptr;
-     	is_equal_function(&res, *value, entry);
-		if (zval_is_true(&res)) {
+	while(zend_hash_get_current_data(target_hash, (void **)&entry) == SUCCESS) {
+     	compare_func(&res, *value, *entry);
+		if (Z_LVAL(res) == 1) {
 			RETURN_TRUE;
 		}