xref: /PHP-8.2/Zend/tests/bug39297.phpt (revision 75a678a7)
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): bool {
14    }
15
16    public function offsetUnset($offset): void {
17    }
18
19    public function offsetSet($offset, $value): void {
20        echo "offsetSet()\n";
21        $cannonicalName = strtolower($offset);
22        $this->children[$cannonicalName] = $value;
23        $value->parent = $this;
24    }
25
26    public function offsetGet($offset): mixed {
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