array_access_013.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. ZE2 ArrayAccess and exceptions
  3. --FILE--
  4. <?php
  5. class Test implements ArrayAccess
  6. {
  7. public function offsetExists($offset): bool { throw new Exception(__METHOD__); return false; }
  8. public function offsetGet($offset): mixed { throw new Exception(__METHOD__); return $offset; }
  9. public function offsetSet($offset, $data ): void { throw new Exception(__METHOD__); }
  10. public function offsetUnset($offset): void { 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. --EXPECT--
  47. Caught in Test::offsetExists()
  48. Caught in Test::offsetGet()
  49. Caught in Test::offsetSet()
  50. Caught in Test::offsetUnset()