ArrayAccess_indirect_append.phpt 760 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Using indirect append on ArrayAccess object
  3. --FILE--
  4. <?php
  5. class AA implements ArrayAccess {
  6. private $data = [];
  7. public function &offsetGet($name): mixed {
  8. if (null === $name) {
  9. return $this->data[];
  10. } else {
  11. return $this->data[$name];
  12. }
  13. }
  14. public function offsetSet($name, $value): void {
  15. $this->data[$name] = $value;
  16. }
  17. public function offsetUnset($name): void {}
  18. public function offsetExists($name): bool {}
  19. }
  20. $aa = new AA;
  21. $aa[3] = 1;
  22. $aa[][][0] = 2;
  23. var_dump($aa);
  24. ?>
  25. --EXPECT--
  26. object(AA)#1 (1) {
  27. ["data":"AA":private]=>
  28. array(2) {
  29. [3]=>
  30. int(1)
  31. [4]=>
  32. array(1) {
  33. [0]=>
  34. array(1) {
  35. [0]=>
  36. int(2)
  37. }
  38. }
  39. }
  40. }