Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ PHP NEWS
(Nicolas Grekas)
. Fixed convert.quoted-printable-decode decoding lowercase hex digits to
the wrong byte. (Ilia Alshanetsky)
. Fixed boolean key handling in array_combine(). (arshidkv12)

- Tidy:
. Fixed a use-after-free when a tidyNode is used after its document is
Expand Down
5 changes: 5 additions & 0 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -7187,6 +7187,11 @@ PHP_FUNCTION(array_combine)
if (Z_TYPE_P(entry_keys) == IS_LONG) {
entry_values = zend_hash_index_update(Z_ARRVAL_P(return_value),
Z_LVAL_P(entry_keys), entry_values);
} else if (Z_TYPE_P(entry_keys) == IS_FALSE || Z_TYPE_P(entry_keys) == IS_TRUE) {
entry_values = zend_hash_index_update(Z_ARRVAL_P(return_value),
Z_TYPE_P(entry_keys) == IS_TRUE ? 1 : 0,
entry_values
);
} else {
zend_string *tmp_key;
zend_string *key = zval_get_tmp_string(entry_keys, &tmp_key);
Expand Down
39 changes: 39 additions & 0 deletions ext/standard/tests/array/array_combine_boolean_keys.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
array_combine() with boolean keys compared to direct array keys
--FILE--
<?php

echo "Direct array keys:\n";
var_dump([true => 'true', false => 'false']);

echo "\narray_combine:\n";
var_dump(array_combine([true, false], ['true', 'false']));

echo "\nExplicit integer keys:\n";
var_dump(array_combine([1, 0], ['true', 'false']));

?>
--EXPECT--
Direct array keys:
array(2) {
[1]=>
string(4) "true"
[0]=>
string(5) "false"
}

array_combine:
array(2) {
[1]=>
string(4) "true"
[0]=>
string(5) "false"
}

Explicit integer keys:
array(2) {
[1]=>
string(4) "true"
[0]=>
string(5) "false"
}
Loading