From: Nikita Popov Date: Fri, 12 Apr 2019 11:38:51 +0000 (+0200) Subject: Add test for get_cfg_var with array variable X-Git-Tag: php-7.4.0alpha1~518 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=733c61a89452adc0f8484f19ff1e30a6e4ca30bb;p=php Add test for get_cfg_var with array variable And fix incorrect variable shadowing in add_config_entry(). However, the test doesn't hit this case, as it requires a nested array. I'm not sure if it's possible to produce nested arrays from ini? --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 29ee2fb3f2..c78de74f2f 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4690,6 +4690,8 @@ PHP_FUNCTION(get_current_user) } /* }}} */ +static void add_config_entries(HashTable *hash, zval *return_value); + /* {{{ add_config_entry */ static void add_config_entry(zend_ulong h, zend_string *key, zval *entry, zval *retval) @@ -4701,14 +4703,9 @@ static void add_config_entry(zend_ulong h, zend_string *key, zval *entry, zval * add_index_str(retval, h, zend_string_copy(Z_STR_P(entry))); } } else if (Z_TYPE_P(entry) == IS_ARRAY) { - zend_ulong h; - zend_string *key; - zval *zv, tmp; - + zval tmp; array_init(&tmp); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(entry), h, key, zv) - add_config_entry(h, key, zv, &tmp); - ZEND_HASH_FOREACH_END(); + add_config_entries(Z_ARRVAL_P(entry), &tmp); zend_hash_update(Z_ARRVAL_P(retval), key, &tmp); } } diff --git a/ext/standard/tests/general_functions/get_cfg_var_array.phpt b/ext/standard/tests/general_functions/get_cfg_var_array.phpt new file mode 100644 index 0000000000..720e635885 --- /dev/null +++ b/ext/standard/tests/general_functions/get_cfg_var_array.phpt @@ -0,0 +1,27 @@ +--TEST-- +Using get_cfg_var() on an array ini value +--INI-- +ary[a] = 1 +ary[b] = 2 +ary2[1] = a +ary2[2] = b +--FILE-- + +--EXPECT-- +array(2) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" +} +array(2) { + [1]=> + string(1) "a" + [2]=> + string(1) "b" +}