Skip to content

Commit daadeb2

Browse files
committed
ext/standard: Fix boolean keys in array_combine()
ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine() ext/standard: Fix boolean keys in array_combine()
1 parent f735f33 commit daadeb2

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ PHP NEWS
294294
(Nicolas Grekas)
295295
. Fixed convert.quoted-printable-decode decoding lowercase hex digits to
296296
the wrong byte. (Ilia Alshanetsky)
297+
. Fixed boolean key handling in array_combine(). (arshidkv12)
297298

298299
- Tidy:
299300
. Fixed a use-after-free when a tidyNode is used after its document is
@@ -3160,5 +3161,4 @@ PHP NEWS
31603161
(nielsdos)
31613162
. Fix trampoline leak in xpath callables. (nielsdos)
31623163

3163-
- Zip:
3164-
. Added ZipArchive::ER_TRUNCATED_ZIP added in libzip 1.11. (Remi)
3164+
- Zip:

‎ext/standard/array.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7187,6 +7187,11 @@ PHP_FUNCTION(array_combine)
71877187
if (Z_TYPE_P(entry_keys) == IS_LONG) {
71887188
entry_values = zend_hash_index_update(Z_ARRVAL_P(return_value),
71897189
Z_LVAL_P(entry_keys), entry_values);
7190+
} else if (Z_TYPE_P(entry_keys) == IS_FALSE || Z_TYPE_P(entry_keys) == IS_TRUE) {
7191+
entry_values = zend_hash_index_update(Z_ARRVAL_P(return_value),
7192+
Z_TYPE_P(entry_keys) == IS_TRUE ? 1 : 0,
7193+
entry_values
7194+
);
71907195
} else {
71917196
zend_string *tmp_key;
71927197
zend_string *key = zval_get_tmp_string(entry_keys, &tmp_key);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
array_combine() with boolean keys compared to direct array keys
3+
--FILE--
4+
<?php
5+
6+
echo "Direct array keys:\n";
7+
var_dump([true => 'true', false => 'false']);
8+
9+
echo "\narray_combine:\n";
10+
var_dump(array_combine([true, false], ['true', 'false']));
11+
12+
echo "\nExplicit integer keys:\n";
13+
var_dump(array_combine([1, 0], ['true', 'false']));
14+
15+
?>
16+
--EXPECT--
17+
Direct array keys:
18+
array(2) {
19+
[1]=>
20+
string(4) "true"
21+
[0]=>
22+
string(5) "false"
23+
}
24+
25+
array_combine:
26+
array(2) {
27+
[1]=>
28+
string(4) "true"
29+
[0]=>
30+
string(5) "false"
31+
}
32+
33+
Explicit integer keys:
34+
array(2) {
35+
[1]=>
36+
string(4) "true"
37+
[0]=>
38+
string(5) "false"
39+
}

0 commit comments

Comments
 (0)