Skip to content

Commit 733c61a

Browse files
committed
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?
1 parent afee7ed commit 733c61a

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

ext/standard/basic_functions.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4690,6 +4690,8 @@ PHP_FUNCTION(get_current_user)
46904690
}
46914691
/* }}} */
46924692

4693+
static void add_config_entries(HashTable *hash, zval *return_value);
4694+
46934695
/* {{{ add_config_entry
46944696
*/
46954697
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 *
47014703
add_index_str(retval, h, zend_string_copy(Z_STR_P(entry)));
47024704
}
47034705
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
4704-
zend_ulong h;
4705-
zend_string *key;
4706-
zval *zv, tmp;
4707-
4706+
zval tmp;
47084707
array_init(&tmp);
4709-
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(entry), h, key, zv)
4710-
add_config_entry(h, key, zv, &tmp);
4711-
ZEND_HASH_FOREACH_END();
4708+
add_config_entries(Z_ARRVAL_P(entry), &tmp);
47124709
zend_hash_update(Z_ARRVAL_P(retval), key, &tmp);
47134710
}
47144711
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Using get_cfg_var() on an array ini value
3+
--INI--
4+
ary[a] = 1
5+
ary[b] = 2
6+
ary2[1] = a
7+
ary2[2] = b
8+
--FILE--
9+
<?php
10+
11+
var_dump(get_cfg_var('ary'));
12+
var_dump(get_cfg_var('ary2'));
13+
14+
?>
15+
--EXPECT--
16+
array(2) {
17+
["a"]=>
18+
string(1) "1"
19+
["b"]=>
20+
string(1) "2"
21+
}
22+
array(2) {
23+
[1]=>
24+
string(1) "a"
25+
[2]=>
26+
string(1) "b"
27+
}

0 commit comments

Comments
 (0)