bug64417.phpt 893 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Bug #64417 (BC break: ArrayAccess::&offsetGet() in a trait causes fatal error)
  3. --FILE--
  4. <?php
  5. trait aa {
  6. private $container = array();
  7. public function offsetSet($offset, $value): void {
  8. if (is_null($offset)) {
  9. $this->container[] = $value;
  10. } else {
  11. $this->container[$offset] = $value;
  12. }
  13. }
  14. public function offsetExists($offset): bool {
  15. return isset($this->container[$offset]);
  16. }
  17. public function offsetUnset($offset): void {
  18. unset($this->container[$offset]);
  19. }
  20. public function &offsetGet($offset): mixed {
  21. $result = null;
  22. if (isset($this->container[$offset])) {
  23. $result = &$this->container[$offset];
  24. }
  25. return $result;
  26. }
  27. }
  28. class obj implements ArrayAccess {
  29. use aa;
  30. }
  31. $o = new obj;
  32. $o['x'] = 1;
  33. ++$o['x'];
  34. echo $o['x'], "\n";
  35. ?>
  36. --EXPECT--
  37. 2