bug69957.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. --TEST--
  2. Bug #69957 (Different ways of handling div/mod by zero)
  3. --FILE--
  4. <?php
  5. try {
  6. $divisor = 0;
  7. $result = 1 / $divisor;
  8. var_dump($result);
  9. } catch (DivisionByZeroError $t){
  10. echo "Variable div\n";
  11. printf("Type: %s\n", get_class($t));
  12. printf("Message: %s\n", $t->getMessage());
  13. }
  14. try {
  15. $divisor = 0;
  16. $result = 1 % $divisor;
  17. var_dump($result);
  18. } catch (DivisionByZeroError $t){
  19. echo "\nVariable mod\n";
  20. printf("Type: %s\n", get_class($t));
  21. printf("Message: %s\n", $t->getMessage());
  22. }
  23. try {
  24. $result = 1 / 0;
  25. var_dump($result);
  26. } catch (DivisionByZeroError $t){
  27. echo "\nLiteral div\n";
  28. printf("Type: %s\n", get_class($t));
  29. printf("Message: %s\n", $t->getMessage());
  30. }
  31. try {
  32. $result = 1 % 0;
  33. var_dump($result);
  34. } catch (DivisionByZeroError $t){
  35. echo "\nLiteral mod\n";
  36. printf("Type: %s\n", get_class($t));
  37. printf("Message: %s\n", $t->getMessage());
  38. }
  39. try {
  40. $result = 1 / 0.0;
  41. var_dump($result);
  42. } catch (DivisionByZeroError $t){
  43. echo "\nDouble div\n";
  44. printf("Type: %s\n", get_class($t));
  45. printf("Message: %s\n", $t->getMessage());
  46. }
  47. try {
  48. $result = 1 % 0.0;
  49. var_dump($result);
  50. } catch (DivisionByZeroError $t){
  51. echo "\nDouble mod\n";
  52. printf("Type: %s\n", get_class($t));
  53. printf("Message: %s\n", $t->getMessage());
  54. }
  55. ?>
  56. --EXPECT--
  57. Variable div
  58. Type: DivisionByZeroError
  59. Message: Division by zero
  60. Variable mod
  61. Type: DivisionByZeroError
  62. Message: Modulo by zero
  63. Literal div
  64. Type: DivisionByZeroError
  65. Message: Division by zero
  66. Literal mod
  67. Type: DivisionByZeroError
  68. Message: Modulo by zero
  69. Double div
  70. Type: DivisionByZeroError
  71. Message: Division by zero
  72. Double mod
  73. Type: DivisionByZeroError
  74. Message: Modulo by zero