xref: /PHP-7.4/Zend/tests/bug69957.phpt (revision d679f022)
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--EXPECTF--
64Warning: Division by zero in %sbug69957.php on line %d
65float(INF)
66
67Variable mod
68Type: DivisionByZeroError
69Message: Modulo by zero
70
71Warning: Division by zero in %sbug69957.php on line %d
72float(INF)
73
74Literal mod
75Type: DivisionByZeroError
76Message: Modulo by zero
77
78Warning: Division by zero in %sbug69957.php on line %d
79float(INF)
80
81Double mod
82Type: DivisionByZeroError
83Message: Modulo by zero
84