1--TEST--
2WeakReference overwriting existing value
3--FILE--
4<?php
5
6class HasDtor {
7    public function __destruct() {
8        echo "In destruct\n";
9        global $w, $all;
10        for ($i = 0; $i < 10; $i++) {
11            $v = new stdClass();
12            $all[] = $v;
13            $w[$v] = $i;
14        }
15    }
16}
17$all = [];
18$w = new WeakMap();
19$o = new stdClass();
20
21$w[$o] = new HasDtor();
22$w[$o] = 123;
23var_dump($w);
24?>
25--EXPECT--
26In destruct
27object(WeakMap)#1 (11) {
28  [0]=>
29  array(2) {
30    ["key"]=>
31    object(stdClass)#2 (0) {
32    }
33    ["value"]=>
34    int(123)
35  }
36  [1]=>
37  array(2) {
38    ["key"]=>
39    object(stdClass)#4 (0) {
40    }
41    ["value"]=>
42    int(0)
43  }
44  [2]=>
45  array(2) {
46    ["key"]=>
47    object(stdClass)#5 (0) {
48    }
49    ["value"]=>
50    int(1)
51  }
52  [3]=>
53  array(2) {
54    ["key"]=>
55    object(stdClass)#6 (0) {
56    }
57    ["value"]=>
58    int(2)
59  }
60  [4]=>
61  array(2) {
62    ["key"]=>
63    object(stdClass)#7 (0) {
64    }
65    ["value"]=>
66    int(3)
67  }
68  [5]=>
69  array(2) {
70    ["key"]=>
71    object(stdClass)#8 (0) {
72    }
73    ["value"]=>
74    int(4)
75  }
76  [6]=>
77  array(2) {
78    ["key"]=>
79    object(stdClass)#9 (0) {
80    }
81    ["value"]=>
82    int(5)
83  }
84  [7]=>
85  array(2) {
86    ["key"]=>
87    object(stdClass)#10 (0) {
88    }
89    ["value"]=>
90    int(6)
91  }
92  [8]=>
93  array(2) {
94    ["key"]=>
95    object(stdClass)#11 (0) {
96    }
97    ["value"]=>
98    int(7)
99  }
100  [9]=>
101  array(2) {
102    ["key"]=>
103    object(stdClass)#12 (0) {
104    }
105    ["value"]=>
106    int(8)
107  }
108  [10]=>
109  array(2) {
110    ["key"]=>
111    object(stdClass)#13 (0) {
112    }
113    ["value"]=>
114    int(9)
115  }
116}