xref: /PHP-5.5/Zend/tests/bug39297.phpt (revision 610c7fbe)
1--TEST--
2Bug #39297 (Memory corryption because of indirect modification of overloaded array)
3--FILE--
4<?php
5function compareByRef(&$first, &$second) {
6    return $first === $second;
7}
8
9class MyTree implements ArrayAccess {
10    public $parent;
11    public $children = array();
12
13    public function offsetExists($offset) {
14    }
15
16    public function offsetUnset($offset) {
17    }
18
19    public function offsetSet($offset, $value) {
20    	echo "offsetSet()\n";
21        $cannonicalName = strtolower($offset);
22        $this->children[$cannonicalName] = $value;
23        $value->parent = $this;
24    }
25
26    public function offsetGet($offset) {
27    	echo "offsetGet()\n";
28        $cannonicalName = strtolower($offset);
29        return $this->children[$cannonicalName];
30    }
31
32}
33
34$id = 'Test';
35
36$root = new MyTree();
37$child = new MyTree();
38$root[$id] = $child;
39
40var_dump(compareByRef($root[$id], $child));
41?>
42--EXPECT--
43offsetSet()
44offsetGet()
45bool(true)
46