From: Dmitry Stogov Date: Wed, 10 Aug 2005 07:44:10 +0000 (+0000) Subject: Fixed bug #29253 (array_diff with $GLOBALS argument fails) X-Git-Tag: php-4.4.1RC1~72 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=674236d9ab50ade97de1d0d3374dc9dfb25c60d9;p=php Fixed bug #29253 (array_diff with $GLOBALS argument fails) --- diff --git a/NEWS b/NEWS index 1244197137..0a9c3ec3f4 100644 --- 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) diff --git a/ext/standard/array.c b/ext/standard/array.c index 7637e24552..e74022cfd7 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -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 index 0000000000..a495d65cfc --- /dev/null +++ b/ext/standard/tests/array/bug29253.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #29253 array_diff with $GLOBALS argument fails +--FILE-- + +--EXPECT-- +array(0) { +} +string(4) "afad"