bug39297.phpt 970 B

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