zkeyval = array_column_fetch_prop(data, zkey, &rvk);
}
if (zkeyval) {
- if (Z_TYPE_P(zkeyval) == IS_STRING) {
- zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(zkeyval), zcolval);
- } else if (Z_TYPE_P(zkeyval) == IS_LONG) {
- add_index_zval(return_value, Z_LVAL_P(zkeyval), zcolval);
- } else if (Z_TYPE_P(zkeyval) == IS_OBJECT) {
- zend_string *key = zval_get_string(zkeyval);
- zend_symtable_update(Z_ARRVAL_P(return_value), key, zcolval);
- zend_string_release(key);
- } else {
- add_next_index_zval(return_value, zcolval);
+ switch (Z_TYPE_P(zkeyval)) {
+ case IS_STRING:
+ zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(zkeyval), zcolval);
+ break;
+ case IS_LONG:
+ zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(zkeyval), zcolval);
+ break;
+ case IS_OBJECT:
+ {
+ zend_string *key = zval_get_string(zkeyval);
+ zend_symtable_update(Z_ARRVAL_P(return_value), key, zcolval);
+ zend_string_release(key);
+ break;
+ }
+ case IS_NULL:
+ zend_hash_update(Z_ARRVAL_P(return_value), ZSTR_EMPTY_ALLOC(), zcolval);
+ break;
+ case IS_DOUBLE:
+ zend_hash_index_update(Z_ARRVAL_P(return_value), zend_dval_to_lval(Z_DVAL_P(zkeyval)), zcolval);
+ break;
+ case IS_TRUE:
+ zend_hash_index_update(Z_ARRVAL_P(return_value), 1, zcolval);
+ break;
+ case IS_FALSE:
+ zend_hash_index_update(Z_ARRVAL_P(return_value), 0, zcolval);
+ break;
+ case IS_RESOURCE:
+ zend_hash_index_update(Z_ARRVAL_P(return_value), Z_RES_HANDLE_P(zkeyval), zcolval);
+ break;
+ default:
+ add_next_index_zval(return_value, zcolval);
+ break;
}
if (zkeyval == &rvk) {
zval_ptr_dtor(&rvk);
--- /dev/null
+--TEST--
+Bug #68553 (array_column: null values in $index_key become incrementing keys in result)
+--FILE--
+<?php
+$i = 100;
+/* increase the resource id to make test stable */
+while ($i--) {
+ $fd = fopen(__FILE__, "r");
+ fclose($fd);
+}
+$a = [
+ ['a' => 10],
+ ['a' => 20],
+ ['a' => true],
+ ['a' => false],
+ ['a' => fopen(__FILE__, "r")],
+ ['a' => -5],
+ ['a' => 7.38],
+ ['a' => null, "test"],
+ ['a' => null],
+];
+
+var_dump(array_column($a, null, 'a'));
+--EXPECTF--
+array(8) {
+ [10]=>
+ array(1) {
+ ["a"]=>
+ int(10)
+ }
+ [20]=>
+ array(1) {
+ ["a"]=>
+ int(20)
+ }
+ [1]=>
+ array(1) {
+ ["a"]=>
+ bool(true)
+ }
+ [0]=>
+ array(1) {
+ ["a"]=>
+ bool(false)
+ }
+ [%d]=>
+ array(1) {
+ ["a"]=>
+ resource(%d) of type (stream)
+ }
+ [-5]=>
+ array(1) {
+ ["a"]=>
+ int(-5)
+ }
+ [7]=>
+ array(1) {
+ ["a"]=>
+ float(7.38)
+ }
+ [""]=>
+ array(1) {
+ ["a"]=>
+ NULL
+ }
+}