array_access_012.phpt 946 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. ZE2 ArrayAccess cannot assign by reference
  3. --FILE--
  4. <?php
  5. class ArrayAccessImpl implements ArrayAccess {
  6. private $data = array();
  7. public function offsetUnset($index): void {}
  8. public function offsetSet($index, $value): void {
  9. $this->data[$index] = $value;
  10. }
  11. public function offsetGet($index): mixed {
  12. return $this->data[$index];
  13. }
  14. public function offsetExists($index): bool {
  15. return isset($this->data[$index]);
  16. }
  17. }
  18. $data = new ArrayAccessImpl();
  19. $test = 'some data';
  20. $data['element'] = NULL; // prevent notice
  21. $data['element'] = &$test;
  22. ?>
  23. ===DONE===
  24. --EXPECTF--
  25. Notice: Indirect modification of overloaded element of ArrayAccessImpl has no effect in %sarray_access_012.php on line 24
  26. Fatal error: Uncaught Error: Cannot assign by reference to an array dimension of an object in %sarray_access_012.php:24
  27. Stack trace:
  28. #0 {main}
  29. thrown in %sarray_access_012.php on line 24