Fix division by zero to throw exception
| From: | Dmitry Stogov | Date: | Fri, 03 Apr 2015 19:04:52 +0000 |
| Subject: | Fix division by zero to throw exception | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-85716@lists.php.net to get a copy of this message | ||
1) Division by zero behavior in PHP is really inconsistent.
It emits WARNING and returns FALLE.
Note, that since PHP-5.6 division by zero may also occur in constant
expressions. They are compiled and evaluated only once (on first request)
and on next request WARNING is going to be hidden.
$ cat div.php
<?php
class C {
const T = 5 / 0;
}
var_dump(C::T);
?>
$ sapi/cgi/php-cgi -q -T 3 div.php
PHP Warning: Division by zero in
/home/dmitry/php/php-master/CGI-DEBUG/div.php on line 3
bool(false)
bool(false)
bool(false)
I propose to change this into fatal error for division by zero at
compile-time and exception a run-time.
2) Very similar weird behavior was introduced for shift with negative
offsets. I also propose to change it in the same way (Fatal error at
compile-time, Exception in run-time).
Any thoughts? objections?
Thanks. Dmitry.