1--TEST--
2Self-referencing map entry GC - 004
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] = [$map, $obj];
14$ref = WeakReference::create($map);
15
16gc_collect_cycles();
17
18var_dump($ref->get());
19
20gc_collect_cycles();
21
22// $map is first in the root buffer
23$map = null;
24$obj = 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      *RECURSION*
43      [1]=>
44      object(Value)#%d (1) {
45        ["value"]=>
46        string(1) "a"
47      }
48    }
49  }
50}
51NULL
52