summaryrefslogtreecommitdiff
path: root/Zend/tests/bug69957.phpt
blob: d72d588978fbbf5995019f7f7d43f3b67d14ae8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
--TEST--
Bug #69957 (Different ways of handling div/mod by zero)
--FILE--
<?php

try {
    $divisor = 0;
    $result = 1 / $divisor;
    var_dump($result);
} catch (DivisionByZeroError $t){
    echo "Variable div\n";
    printf("Type: %s\n", get_class($t));
    printf("Message: %s\n", $t->getMessage());
}

try {
    $divisor = 0;
    $result = 1 % $divisor;
    var_dump($result);
} catch (DivisionByZeroError $t){
    echo "\nVariable mod\n";
    printf("Type: %s\n", get_class($t));
    printf("Message: %s\n", $t->getMessage());
}

try {
    $result = 1 / 0;
    var_dump($result);
} catch (DivisionByZeroError $t){
    echo "\nLiteral div\n";
    printf("Type: %s\n", get_class($t));
    printf("Message: %s\n", $t->getMessage());
}

try {
    $result = 1 % 0;
    var_dump($result);
} catch (DivisionByZeroError $t){
    echo "\nLiteral mod\n";
    printf("Type: %s\n", get_class($t));
    printf("Message: %s\n", $t->getMessage());
}

try {
    $result = 1 / 0.0;
    var_dump($result);
} catch (DivisionByZeroError $t){
    echo "\nDouble div\n";
    printf("Type: %s\n", get_class($t));
    printf("Message: %s\n", $t->getMessage());
}

try {
    $result = 1 % 0.0;
    var_dump($result);
} catch (DivisionByZeroError $t){
    echo "\nDouble mod\n";
    printf("Type: %s\n", get_class($t));
    printf("Message: %s\n", $t->getMessage());
}

?>
--EXPECT--
Variable div
Type: DivisionByZeroError
Message: Division by zero

Variable mod
Type: DivisionByZeroError
Message: Modulo by zero

Literal div
Type: DivisionByZeroError
Message: Division by zero

Literal mod
Type: DivisionByZeroError
Message: Modulo by zero

Double div
Type: DivisionByZeroError
Message: Division by zero

Double mod
Type: DivisionByZeroError
Message: Modulo by zero