xref: /PHP-7.4/Zend/tests/bug70321.phpt (revision 55f88141)
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) {
19		$bar = $this->bar;
20		return $bar;
21	}
22	public function offsetSet($key, $val) {
23	}
24	public function offsetUnset($key) {
25	}
26	public function offsetExists($key) {
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 (0) {
43  }
44}
45array(1) {
46  [0]=>
47  object(Closure)#%d (0) {
48  }
49}
50