1--TEST--
2Self-referencing map entry GC - 003
3--FILE--
4<?php
5
6class Value {
7    public function __construct(public readonly string $value) {
8    }
9}
10
11$map = new WeakMap();
12$obj = new Value('a');
13$map[$obj] = [$obj, $map];
14$ref = WeakReference::create($map);
15
16gc_collect_cycles();
17
18var_dump($ref->get());
19
20gc_collect_cycles();
21
22// $obj is first in the root buffer
23$obj = null;
24$map = null;
25gc_collect_cycles();
26
27var_dump($ref->get());
28
29?>
30--EXPECTF--
31object(WeakMap)#%d (1) {
32  [0]=>
33  array(2) {
34    ["key"]=>
35    object(Value)#%d (1) {
36      ["value"]=>
37      string(1) "a"
38    }
39    ["value"]=>
40    array(2) {
41      [0]=>
42      object(Value)#%d (1) {
43        ["value"]=>
44        string(1) "a"
45      }
46      [1]=>
47      *RECURSION*
48    }
49  }
50}
51NULL
52