From 674236d9ab50ade97de1d0d3374dc9dfb25c60d9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 10 Aug 2005 07:44:10 +0000 Subject: [PATCH] Fixed bug #29253 (array_diff with $GLOBALS argument fails) --- NEWS | 1 + ext/standard/array.c | 18 ++++++++++++++++++ ext/standard/tests/array/bug29253.phpt | 13 +++++++++++++ 3 files changed, 32 insertions(+) create mode 100755 ext/standard/tests/array/bug29253.phpt 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" -- 2.50.1