1--TEST--
2Coalesce assign (??=): ArrayAccess handling
3--FILE--
4<?php
5
6function id($arg) {
7    echo "id($arg)\n";
8    return $arg;
9}
10
11class AA implements ArrayAccess {
12    public $data;
13    public function __construct($data = []) {
14        $this->data = $data;
15    }
16    public function &offsetGet($k): mixed {
17        echo "offsetGet($k)\n";
18        return $this->data[$k];
19    }
20    public function offsetExists($k): bool {
21        echo "offsetExists($k)\n";
22        return array_key_exists($k, $this->data);
23    }
24    public function offsetSet($k,$v): void {
25        echo "offsetSet($k,$v)\n";
26        $this->data[$k] = $v;
27    }
28    public function offsetUnset($k): void { }
29}
30
31$ary = new AA(["foo" => new AA, "null" => null]);
32
33echo "[foo]\n";
34$ary["foo"] ??= "bar";
35
36echo "[bar]\n";
37$ary["bar"] ??= "foo";
38
39echo "[null]\n";
40$ary["null"] ??= "baz";
41
42echo "[foo][bar]\n";
43$ary["foo"]["bar"] ??= "abc";
44
45echo "[foo][bar]\n";
46$ary["foo"]["bar"] ??= "def";
47
48?>
49--EXPECT--
50[foo]
51offsetExists(foo)
52offsetGet(foo)
53[bar]
54offsetExists(bar)
55offsetSet(bar,foo)
56[null]
57offsetExists(null)
58offsetGet(null)
59offsetSet(null,baz)
60[foo][bar]
61offsetExists(foo)
62offsetGet(foo)
63offsetExists(bar)
64offsetGet(foo)
65offsetSet(bar,abc)
66[foo][bar]
67offsetExists(foo)
68offsetGet(foo)
69offsetExists(bar)
70offsetGet(bar)
71