Req #71306 [ReO]: Remove Division by zero warning from "/" operator
Edit report at https://bugs.php.net/bug.php?id=71306&edit=1
ID: 71306
Updated by: ajf@php.net
Reported by: hungry dot rahly at gmail dot com
Summary: Remove Division by zero warning from "/" operator
Status: Re-Opened
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: irrelevant
PHP Version: irrelevant
Block user comment: N
Private report: N
New Comment:
Interestingly fmod() doesn't produce a warning here, so if we got rid of the warning for
/ then we'd bring the two into alignment.
Previous Comments:
------------------------------------------------------------------------
[2016-03-10 13:08:16] axiac dot ro at gmail dot com
It would be great to have this behaviour (who throws the exception and who doesn't) explained
in the documentation of the DivisionByZeroError exception.
I submitted a patch on the documentation site that adds this information.
------------------------------------------------------------------------
[2016-01-09 00:24:18] yohgaki@php.net
Make this a change request.
------------------------------------------------------------------------
[2016-01-08 00:49:20] hungry dot rahly at gmail dot com
Then a removal of the warning would be best, because with the warning, you are saying there is a
problem, when in fact, there isn't.
------------------------------------------------------------------------
[2016-01-08 00:43:06] bwoebi@php.net
This indeed is expected behavior; the only possible thing eventually subject to change in future is
whether the warning will be removed.
But a DivisionByZeroError is definitely not suitable here as divisions by zero are handled like
floating point divisions. (Yielding ±INF or NaN)
Just for integer divisions (intdiv) and modulo, there's no valid result, hence an exception is
then thrown (instead of false like before).
------------------------------------------------------------------------
[2016-01-07 23:27:19] hungry dot rahly at gmail dot com
Description:
------------
It doesn't seem to throw an exception for an ACTUAL division of 0 ($var1 / $var2) and still
presents as a warning
Test script:
---------------
<?php
echo PHP_VERSION."\n";
$x = 5;
$y = 0;
try {
print "here1\n";
$z = $x % $y;
print "here2 - $z\n";
} catch(Error $e) {
print "here ERROR 1 ".get_class($e)."\n";
}
try {
print "here3\n";
$z = $x / $y;
print "here4 - $z\n";
} catch(Error $e) {
print "here ERROR 2 ".get_class($e)."\n";
}
try {
print "here5\n";
$x = intdiv((int)$x, $y);
print "here6 - $z\n";
} catch(Error $e) {
print "here ERROR 3 ".get_class($e). "\n";
}
Expected result:
----------------
7.0.2
here1
here ERROR 1 DivisionByZeroError
here3
here ERROR 2 DivisionByZeroError
here5
here ERROR 3 DivisionByZeroError
Actual result:
--------------
7.0.2
here1
here ERROR 1 DivisionByZeroError
here3
PHP Warning: Division by zero in test.php on line 17
here4 - INF
here5
here ERROR 3 DivisionByZeroError
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71306&edit=1
Thread (7 messages)