forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring_keys.phpt
69 lines (63 loc) · 983 Bytes
/
string_keys.phpt
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
--TEST--
Array unpacking with string keys
--FILE--
<?php
// Works with both arrays and Traversables.
$array = [1, 2, "foo" => 3, 4];
var_dump([...$array]);
$iterator = new ArrayIterator([1, 2, "foo" => 3, 4]);
var_dump([...$iterator]);
// Test overwriting behavior.
$array1 = ["foo" => 1];
$array2 = ["foo" => 2];
var_dump(["foo" => 0, ...$array1, ...$array2]);
var_dump(["foo" => 0, ...$array1, ...$array2, "foo" => 3]);
// Test numeric string key from iterator.
function gen() {
yield "42" => 42;
}
var_dump([...gen()]);
// Same as previous, but with refcounted string.
function gen2() {
$foo = "2";
yield "4" . $foo => 42;
}
var_dump([...gen2()]);
?>
--EXPECT--
array(4) {
[0]=>
int(1)
[1]=>
int(2)
["foo"]=>
int(3)
[2]=>
int(4)
}
array(4) {
[0]=>
int(1)
[1]=>
int(2)
["foo"]=>
int(3)
[2]=>
int(4)
}
array(1) {
["foo"]=>
int(2)
}
array(1) {
["foo"]=>
int(3)
}
array(1) {
[0]=>
int(42)
}
array(1) {
[0]=>
int(42)
}