note 125564 deleted from class.divisionbyzeroerror by cmb
| From: | cmb@php.net | Date: | Thu, 03 Dec 2020 09:38:15 +0000 |
| Subject: | note 125564 deleted from class.divisionbyzeroerror by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215930@lists.php.net to get a copy of this message | ||
Note Submitter: 8ctopus
----
Use of arithmetic operator / does not throw an exception in php 7, while it does in php 8.
<?php
try {
echo intdiv(2, 0);
} catch (DivisionByZeroError $e) {
echo "Caught DivisionByZeroError!\n";
}
try {
echo (2 / 0);
} catch (DivisionByZeroError $e) {
echo "Caught DivisionByZeroError!\n";
}
?>
# php 7
$ php test.php
caught division by zero for intdiv()
PHP Warning: Division by zero in test.php on line 10
PHP Stack trace:
PHP 1. {main}() test.php:0
Warning: Division by zero in test.php on line 10
Call Stack:
0.0740 417272 1. {main}() test.php:0
# php 8
$ php test.php
caught division by zero for intdiv()
caught division by zero for /