bug32134.phpt 868 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Bug #32134 (Overloading offsetGet/offsetSet)
  3. --FILE--
  4. <?php
  5. class myArray extends ArrayIterator
  6. {
  7. public function __construct($array = array())
  8. {
  9. parent::__construct($array);
  10. }
  11. public function offsetGet($index): mixed
  12. {
  13. static $i = 0;
  14. echo __METHOD__ . "($index)\n";
  15. if (++$i > 3) exit(1);
  16. return parent::offsetGet($index);
  17. }
  18. public function offsetSet($index, $newval): void
  19. {
  20. echo __METHOD__ . "($index,$newval)\n";
  21. parent::offsetSet($index, $newval);
  22. }
  23. }
  24. $myArray = new myArray();
  25. $myArray->offsetSet('one', 'one');
  26. var_dump($myArray->offsetGet('one'));
  27. $myArray['two'] = 'two';
  28. var_dump($myArray['two']);
  29. ?>
  30. --EXPECT--
  31. myArray::offsetSet(one,one)
  32. myArray::offsetGet(one)
  33. string(3) "one"
  34. myArray::offsetSet(two,two)
  35. myArray::offsetGet(two)
  36. string(3) "two"