array_access_003.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. ZE2 ArrayAccess::offsetGet ambiguties
  3. --INI--
  4. error_reporting=4095
  5. --FILE--
  6. <?php
  7. class object implements ArrayAccess {
  8. public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
  9. function offsetExists($index) {
  10. echo __METHOD__ . "($index)\n";
  11. return array_key_exists($index, $this->a);
  12. }
  13. function offsetGet($index) {
  14. echo __METHOD__ . "($index)\n";
  15. switch($index) {
  16. case 1:
  17. $a = 'foo';
  18. return $a . 'Bar';
  19. case 2:
  20. static $a=1;
  21. return $a;
  22. }
  23. return $this->a[$index];
  24. }
  25. function offsetSet($index, $newval) {
  26. echo __METHOD__ . "($index,$newval)\n";
  27. if ($index==3) {
  28. $this->cnt = $newval;
  29. }
  30. return $this->a[$index] = $newval;
  31. }
  32. function offsetUnset($index) {
  33. echo __METHOD__ . "($index)\n";
  34. unset($this->a[$index]);
  35. }
  36. }
  37. $obj = new Object;
  38. var_dump($obj[1]);
  39. var_dump($obj[2]);
  40. $obj[2]++;
  41. var_dump($obj[2]);
  42. ?>
  43. ===DONE===
  44. --EXPECTF--
  45. object::offsetGet(1)
  46. string(6) "fooBar"
  47. object::offsetGet(2)
  48. int(1)
  49. object::offsetGet(2)
  50. Notice: Indirect modification of overloaded element of object has no effect in %sarray_access_003.php on line 39
  51. object::offsetGet(2)
  52. int(1)
  53. ===DONE===