summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-04-12 13:38:51 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-04-12 15:12:39 +0200
commit733c61a89452adc0f8484f19ff1e30a6e4ca30bb (patch)
treee10b56cecb8be859065a37256995ec6783f291c8
parentafee7ed110b970f64e6f5d3139262097c462ceae (diff)
downloadphp-git-733c61a89452adc0f8484f19ff1e30a6e4ca30bb.tar.gz
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?
-rw-r--r--ext/standard/basic_functions.c11
-rw-r--r--ext/standard/tests/general_functions/get_cfg_var_array.phpt27
2 files changed, 31 insertions, 7 deletions
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--
+<?php
+
+var_dump(get_cfg_var('ary'));
+var_dump(get_cfg_var('ary2'));
+
+?>
+--EXPECT--
+array(2) {
+ ["a"]=>
+ string(1) "1"
+ ["b"]=>
+ string(1) "2"
+}
+array(2) {
+ [1]=>
+ string(1) "a"
+ [2]=>
+ string(1) "b"
+}