summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/bug68553.phpt
blob: 1d8f7f1b0b4e531b619667975e1e19446644b47d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--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'));

try {
    var_dump(array_column([['a' => new stdClass]], null, 'a'));
} catch (Error $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(array_column([['a' => []]], null, 'a'));
} catch (Error $e) {
    echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
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
  }
}
Illegal offset type
Illegal offset type