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