Bug #71306 [Opn->Nab]: DivisionByZeroError Not Throwing

From: Date: Fri, 08 Jan 2016 00:43:07 +0000
Subject: Bug #71306 [Opn->Nab]: DivisionByZeroError Not Throwing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198508@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:         bwoebi@php.net
 Reported by:        hungry dot rahly at gmail dot com
 Summary:            DivisionByZeroError Not Throwing
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Fedora 22/23/24
 PHP Version:        7.0.2
 Block user comment: N
 Private report:     N

 New Comment:

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).


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#198508) next »