xref: /php-src/Zend/tests/bug70321.phpt (revision 08b2ab22)
1--TEST--
2bug #70321 (Magic getter breaks reference to array property)
3--FILE--
4<?php
5class foo implements arrayAccess
6{
7    private $bar;
8    public function __construct()
9    {
10        $this->bar = new bar();
11    }
12    public function & __get($key)
13    {
14        $bar = $this->bar;
15        return $bar;
16    }
17
18    public function & offsetGet($key): mixed {
19        $bar = $this->bar;
20        return $bar;
21    }
22    public function offsetSet($key, $val): void {
23    }
24    public function offsetUnset($key): void {
25    }
26    public function offsetExists($key): bool {
27    }
28}
29class bar { public $onBaz = []; }
30
31$foo = new foo();
32$foo->bar->onBaz[] = function() {};
33var_dump($foo->bar->onBaz);
34
35$foo = new foo();
36$foo["bar"]->onBaz[] = function() {};
37var_dump($foo->bar->onBaz);
38?>
39--EXPECTF--
40array(1) {
41  [0]=>
42  object(Closure)#%d (3) {
43    ["name"]=>
44    string(%d) "{closure:%s:%d}"
45    ["file"]=>
46    string(%d) "%s"
47    ["line"]=>
48    int(%d)
49  }
50}
51array(1) {
52  [0]=>
53  object(Closure)#%d (3) {
54    ["name"]=>
55    string(%d) "{closure:%s:%d}"
56    ["file"]=>
57    string(%d) "%s"
58    ["line"]=>
59    int(%d)
60  }
61}
62