Index: ext/standard/array.c =================================================================== RCS file: /repository/php-src/ext/standard/array.c,v retrieving revision 1.199.2.21 diff -u -r1.199.2.21 array.c --- ext/standard/array.c 17 Jun 2003 13:20:18 -0000 1.199.2.21 +++ ext/standard/array.c 2 Oct 2003 09:36:16 -0000 @@ -2032,7 +2046,66 @@ return 1; } -static void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive) + + +PHPAPI int php_array_merge_clobber(HashTable *dest, HashTable *src TSRMLS_DC) +{ + zval **src_entry, **dest_entry; + char *string_key; + uint string_key_len; + ulong num_key; + HashPosition pos; + + zend_hash_internal_pointer_reset_ex(src, &pos); + while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) { + switch (zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos)) { + case HASH_KEY_IS_STRING: + if(zend_hash_find(dest, string_key, string_key_len, + (void **)&dest_entry) == SUCCESS) { + if (*src_entry == *dest_entry && ((*dest_entry)->refcount % 2)) { + zend_error(E_WARNING, "%s(): recursion detected!!", + get_active_function_name(TSRMLS_C)); + return 0; + } + if(Z_TYPE_PP(dest_entry) == IS_ARRAY && + Z_TYPE_PP(src_entry) == IS_ARRAY ) { + SEPARATE_ZVAL(dest_entry); + if (!php_array_merge_clobber(Z_ARRVAL_PP(dest_entry), + Z_ARRVAL_PP(src_entry) TSRMLS_CC)) + return 0; + } else { + ZVAL_ADDREF(*src_entry); + zend_hash_update(dest, string_key, strlen(string_key)+1, + src_entry, sizeof(zval *), NULL); + } + }else + { + ZVAL_ADDREF(*src_entry); + zend_hash_update(dest, string_key, strlen(string_key)+1, + src_entry, sizeof(zval *), NULL); + } + break; + + case HASH_KEY_IS_LONG: + ZVAL_ADDREF(*src_entry); + if(zend_hash_index_find(dest, num_key, (void**)&dest_entry) == SUCCESS) { + zend_hash_index_update(dest, num_key, src_entry, sizeof(zval*), NULL); + }else { + zend_hash_next_index_insert(dest, src_entry, sizeof(zval *), NULL); + } + break; + } + + zend_hash_move_forward_ex(src, &pos); + } + + return 1; +} + + + + +static void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive, int clobber) { zval ***args = NULL; int argc, @@ -2056,18 +2129,21 @@ for (i=0; i