]> granicus.if.org Git - php/commitdiff
Fixed bug #29253 (array_diff with $GLOBALS argument fails)
authorDmitry Stogov <dmitry@php.net>
Wed, 10 Aug 2005 07:44:10 +0000 (07:44 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 10 Aug 2005 07:44:10 +0000 (07:44 +0000)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug29253.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 1244197137fcf6079b6c76e2a86c6fde64c29ac2..0a9c3ec3f4a267cf4c75989065480e3f466f1bec 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ PHP 4                                                                      NEWS
   (Nuno)
 - Fixed bug #32160 (copying a file into itself leads to data loss). (Ilia)
 - Fixed bug #31158 (array_splice on $GLOBALS crashes). (Dmitry)
+- Fixed bug #29253 (array_diff with $GLOBALS argument fails). (Dmitry)
 
 11 Jul 2005, Version 4.4.0
 - Added man pages for "phpize" and "php-config" scripts. (Jakub Vrana)
index 7637e245524af17eb8a0e5e61b6dc7099f4dcf50..e74022cfd7117a14fa5616f3f4a23177807a8fc5 100644 (file)
@@ -2622,6 +2622,15 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior)
        /* copy the argument array */
        *return_value = **args[0];
        zval_copy_ctor(return_value);
+       if (return_value->value.ht == &EG(symbol_table)) {
+               HashTable *ht;
+               zval *tmp;
+
+               ALLOC_HASHTABLE(ht);
+               zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
+               zend_hash_copy(ht, return_value->value.ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+               return_value->value.ht = ht;            
+       }
 
        /* go through the lists and look for common values */
        while (*ptrs[0]) {
@@ -2772,6 +2781,15 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior)
        /* copy the argument array */
        *return_value = **args[0];
        zval_copy_ctor(return_value);
+       if (return_value->value.ht == &EG(symbol_table)) {
+               HashTable *ht;
+               zval *tmp;
+
+               ALLOC_HASHTABLE(ht);
+               zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
+               zend_hash_copy(ht, return_value->value.ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+               return_value->value.ht = ht;            
+       }
 
        /* go through the lists and look for values of ptr[0]
                   that are not in the others */
diff --git a/ext/standard/tests/array/bug29253.phpt b/ext/standard/tests/array/bug29253.phpt
new file mode 100755 (executable)
index 0000000..a495d65
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #29253 array_diff with $GLOBALS argument fails 
+--FILE--
+<?php
+$zz = $GLOBALS;
+$gg = 'afad';
+var_dump(array_diff_assoc($GLOBALS, $zz));
+var_dump($gg);
+?>
+--EXPECT--
+array(0) {
+}
+string(4) "afad"