Bug->Req #71306 [Nab->ReO]: Remove Division by zero warning from "/" operator

From: Date: Sat, 09 Jan 2016 00:24:18 +0000
Subject: Bug->Req #71306 [Nab->ReO]: Remove Division by zero warning from "/" operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198539@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71306&edit=1 ID: 71306 Updated by: yohgaki@php.net Reported by: hungry dot rahly at gmail dot com -Summary: DivisionByZeroError Not Throwing +Summary: Remove Division by zero warning from "/" operator -Status: Not a bug +Status: Re-Opened -Type: Bug +Type: Feature/Change Request -Package: Unknown/Other Function +Package: Scripting Engine problem -Operating System: Fedora 22/23/24 +Operating System: irrelevant -PHP Version: 7.0.2 +PHP Version: irrelevant Block user comment: N Private report: N New Comment: Make this a change request. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#198539) next »