bug31185.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. Bug #31185 (Crash when exceptions thrown from ArrayAccess::offsetUnset())
  3. --FILE--
  4. <?php
  5. class FooBar implements ArrayAccess {
  6. private $array = array();
  7. public function offsetExists($index): bool {
  8. return isset($this->array[$index]);
  9. }
  10. public function offsetGet($index): mixed {
  11. return $this->array[$index];
  12. }
  13. public function offsetSet($index, $value): void {
  14. echo __METHOD__ . "($index, $value)\n";
  15. $this->array[$index] = $value;
  16. }
  17. public function offsetUnset($index): void {
  18. throw new Exception('FAIL');
  19. unset($this->array[$index]);
  20. }
  21. }
  22. $i = 0; $j = 0;
  23. $foo = new FooBar();
  24. $foo[$j++] = $i++;
  25. $foo[$j++] = $i++;
  26. $foo[$j++] = $i++;
  27. try
  28. {
  29. unset($foo[1]);
  30. }
  31. catch (Exception $e)
  32. {
  33. echo "CAUGHT: " . $e->getMessage() . "\n";
  34. }
  35. print_R($foo);
  36. ?>
  37. --EXPECT--
  38. FooBar::offsetSet(0, 0)
  39. FooBar::offsetSet(1, 1)
  40. FooBar::offsetSet(2, 2)
  41. CAUGHT: FAIL
  42. FooBar Object
  43. (
  44. [array:FooBar:private] => Array
  45. (
  46. [0] => 0
  47. [1] => 1
  48. [2] => 2
  49. )
  50. )