array_access_013.phpt 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. ZE2 ArrayAccess and exceptions
  3. --FILE--
  4. <?php
  5. class Test implements ArrayAccess
  6. {
  7. public function offsetExists($offset) { throw new Exception(__METHOD__); return false; }
  8. public function offsetGet($offset) { throw new Exception(__METHOD__); return $offset; }
  9. public function offsetSet($offset, $data ) { throw new Exception(__METHOD__); }
  10. public function offsetUnset($offset) { throw new Exception(__METHOD__); }
  11. }
  12. $t = new Test;
  13. try
  14. {
  15. echo isset($t[0]);
  16. }
  17. catch(Exception $e)
  18. {
  19. echo "Caught in " . $e->getMessage() . "()\n";
  20. }
  21. try
  22. {
  23. echo $t[0];
  24. }
  25. catch(Exception $e)
  26. {
  27. echo "Caught in " . $e->getMessage() . "()\n";
  28. }
  29. try
  30. {
  31. $t[0] = 1;
  32. }
  33. catch(Exception $e)
  34. {
  35. echo "Caught in " . $e->getMessage() . "()\n";
  36. }
  37. try
  38. {
  39. unset($t[0]);
  40. }
  41. catch(Exception $e)
  42. {
  43. echo "Caught in " . $e->getMessage() . "()\n";
  44. }
  45. ?>
  46. ===DONE===
  47. --EXPECT--
  48. Caught in Test::offsetExists()
  49. Caught in Test::offsetGet()
  50. Caught in Test::offsetSet()
  51. Caught in Test::offsetUnset()
  52. ===DONE===