Skip to content

Commit 3ca9aaf

Browse files
committed
Merge branch 'PHP-7.2'
* PHP-7.2: Update NEWs Fixed bug #68553 (array_column: null values in $index_key become incrementing keys in result) Conflicts: ext/standard/array.c
2 parents 4799cde + 033dac7 commit 3ca9aaf

File tree

2 files changed

+99
-11
lines changed

2 files changed

+99
-11
lines changed

ext/standard/array.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,17 +4188,39 @@ PHP_FUNCTION(array_column)
41884188
zkeyval = array_column_fetch_prop(data, zkey, &rvk);
41894189
}
41904190
if (zkeyval) {
4191-
if (Z_TYPE_P(zkeyval) == IS_STRING) {
4192-
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(zkeyval), zcolval);
4193-
} else if (Z_TYPE_P(zkeyval) == IS_LONG) {
4194-
add_index_zval(return_value, Z_LVAL_P(zkeyval), zcolval);
4195-
} else if (Z_TYPE_P(zkeyval) == IS_OBJECT) {
4196-
zend_string *tmp_key;
4197-
zend_string *key = zval_get_tmp_string(zkeyval, &tmp_key);
4198-
zend_symtable_update(Z_ARRVAL_P(return_value), key, zcolval);
4199-
zend_tmp_string_release(tmp_key);
4200-
} else {
4201-
add_next_index_zval(return_value, zcolval);
4191+
switch (Z_TYPE_P(zkeyval)) {
4192+
case IS_STRING:
4193+
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(zkeyval), zcolval);
4194+
break;
4195+
case IS_LONG:
4196+
zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(zkeyval), zcolval);
4197+
break;
4198+
case IS_OBJECT:
4199+
{
4200+
zend_string *tmp_key;
4201+
zend_string *key = zval_get_tmp_string(zkeyval, &tmp_key);
4202+
zend_symtable_update(Z_ARRVAL_P(return_value), key, zcolval);
4203+
zend_tmp_string_release(tmp_key);
4204+
break;
4205+
}
4206+
case IS_NULL:
4207+
zend_hash_update(Z_ARRVAL_P(return_value), ZSTR_EMPTY_ALLOC(), zcolval);
4208+
break;
4209+
case IS_DOUBLE:
4210+
zend_hash_index_update(Z_ARRVAL_P(return_value), zend_dval_to_lval(Z_DVAL_P(zkeyval)), zcolval);
4211+
break;
4212+
case IS_TRUE:
4213+
zend_hash_index_update(Z_ARRVAL_P(return_value), 1, zcolval);
4214+
break;
4215+
case IS_FALSE:
4216+
zend_hash_index_update(Z_ARRVAL_P(return_value), 0, zcolval);
4217+
break;
4218+
case IS_RESOURCE:
4219+
zend_hash_index_update(Z_ARRVAL_P(return_value), Z_RES_HANDLE_P(zkeyval), zcolval);
4220+
break;
4221+
default:
4222+
add_next_index_zval(return_value, zcolval);
4223+
break;
42024224
}
42034225
if (zkeyval == &rvk) {
42044226
zval_ptr_dtor(&rvk);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--TEST--
2+
Bug #68553 (array_column: null values in $index_key become incrementing keys in result)
3+
--FILE--
4+
<?php
5+
$i = 100;
6+
/* increase the resource id to make test stable */
7+
while ($i--) {
8+
$fd = fopen(__FILE__, "r");
9+
fclose($fd);
10+
}
11+
$a = [
12+
['a' => 10],
13+
['a' => 20],
14+
['a' => true],
15+
['a' => false],
16+
['a' => fopen(__FILE__, "r")],
17+
['a' => -5],
18+
['a' => 7.38],
19+
['a' => null, "test"],
20+
['a' => null],
21+
];
22+
23+
var_dump(array_column($a, null, 'a'));
24+
--EXPECTF--
25+
array(8) {
26+
[10]=>
27+
array(1) {
28+
["a"]=>
29+
int(10)
30+
}
31+
[20]=>
32+
array(1) {
33+
["a"]=>
34+
int(20)
35+
}
36+
[1]=>
37+
array(1) {
38+
["a"]=>
39+
bool(true)
40+
}
41+
[0]=>
42+
array(1) {
43+
["a"]=>
44+
bool(false)
45+
}
46+
[%d]=>
47+
array(1) {
48+
["a"]=>
49+
resource(%d) of type (stream)
50+
}
51+
[-5]=>
52+
array(1) {
53+
["a"]=>
54+
int(-5)
55+
}
56+
[7]=>
57+
array(1) {
58+
["a"]=>
59+
float(7.38)
60+
}
61+
[""]=>
62+
array(1) {
63+
["a"]=>
64+
NULL
65+
}
66+
}

0 commit comments

Comments
 (0)