update page now
Laravel Live Japan

Voting

: eight plus zero?
(Example: nine)

The Note You're Voting On

8ctopus
5 years ago
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 /

<< Back to user notes page

To Top