xref: /PHP-8.2/ext/standard/tests/array/bug68553.phpt (revision b8e380ab)
1--TEST--
2Bug #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 */
7while ($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
23var_dump(array_column($a, null, 'a'));
24
25try {
26    var_dump(array_column([['a' => new stdClass]], null, 'a'));
27} catch (Error $e) {
28    echo $e->getMessage(), "\n";
29}
30try {
31    var_dump(array_column([['a' => []]], null, 'a'));
32} catch (Error $e) {
33    echo $e->getMessage(), "\n";
34}
35?>
36--EXPECTF--
37Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
38
39Deprecated: Implicit conversion from float 7.38 to int loses precision in %s on line %d
40array(8) {
41  [10]=>
42  array(1) {
43    ["a"]=>
44    int(10)
45  }
46  [20]=>
47  array(1) {
48    ["a"]=>
49    int(20)
50  }
51  [1]=>
52  array(1) {
53    ["a"]=>
54    bool(true)
55  }
56  [0]=>
57  array(1) {
58    ["a"]=>
59    bool(false)
60  }
61  [%d]=>
62  array(1) {
63    ["a"]=>
64    resource(%d) of type (stream)
65  }
66  [-5]=>
67  array(1) {
68    ["a"]=>
69    int(-5)
70  }
71  [7]=>
72  array(1) {
73    ["a"]=>
74    float(7.38)
75  }
76  [""]=>
77  array(1) {
78    ["a"]=>
79    NULL
80  }
81}
82Illegal offset type
83Illegal offset type
84