blob: 1d1f6def8f48dcd18b8365c7789ebae44880d6d2 (
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
|
--TEST--
WeakMap iteration
--FILE--
<?php
$map = new WeakMap;
echo "\nEmpty loop:\n";
foreach ($map as $key => $value) {
var_dump($key, $value);
}
echo "\nSimple loop:\n";
$obj0 = new stdClass;
$obj1 = new stdClass;
$obj2 = new stdClass;
$map[$obj0] = 0;
$map[$obj1] = 1;
$map[$obj2] = 2;
foreach ($map as $key => $value) {
var_dump($key, $value);
}
echo "\nObject removed during loop:\n";
foreach ($map as $key => $value) {
if (isset($obj1) && $key === $obj1) unset($obj1);
var_dump($key, $value);
}
echo "\nBy reference iteration:\n";
foreach ($map as $key => &$value) {
$value++;
}
var_dump($map);
?>
--EXPECT--
Empty loop:
Simple loop:
object(stdClass)#2 (0) {
}
int(0)
object(stdClass)#3 (0) {
}
int(1)
object(stdClass)#4 (0) {
}
int(2)
Object removed during loop:
object(stdClass)#2 (0) {
}
int(0)
object(stdClass)#3 (0) {
}
int(1)
object(stdClass)#4 (0) {
}
int(2)
By reference iteration:
object(WeakMap)#1 (2) {
[0]=>
array(2) {
["key"]=>
object(stdClass)#2 (0) {
}
["value"]=>
&int(1)
}
[1]=>
array(2) {
["key"]=>
object(stdClass)#4 (0) {
}
["value"]=>
&int(3)
}
}
|