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?
This commit is contained in:
Nikita Popov 2019-04-12 13:38:51 +02:00
parent afee7ed110
commit 733c61a894
2 changed files with 31 additions and 7 deletions

View file

@ -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);
}
}

View file

@ -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"
}