xref: /PHP-8.1/Zend/tests/objects_032.phpt (revision 75a678a7)
1--TEST--
2Covariant return-by-ref constraints
3--FILE--
4<?php
5
6class A implements ArrayAccess {
7    public $foo = array();
8
9    public function &offsetGet($n): mixed {
10        return $this->foo[$n];
11    }
12
13    public function offsetSet($n, $v): void {
14    }
15    public function offsetUnset($n): void {
16    }
17    public function offsetExists($n): bool {
18    }
19}
20
21$a = new A;
22
23$a['foo']['bar'] = 2;
24
25var_dump($a);
26
27?>
28--EXPECT--
29object(A)#1 (1) {
30  ["foo"]=>
31  array(1) {
32    ["foo"]=>
33    array(1) {
34      ["bar"]=>
35      int(2)
36    }
37  }
38}
39