Re: Fix division by zero to throw exception

From: Date: Fri, 03 Apr 2015 19:29:24 +0000
Subject: Re: Fix division by zero to throw exception
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-85718@lists.php.net to get a copy of this message
On Fri, Apr 3, 2015 at 9:04 PM, Dmitry Stogov <dmitry@zend.com> wrote: > 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? > I'm okay with making both of these exceptions. It's really weird if dividing two numbers you can suddenly end up with a boolean... Nikita

« previous php.internals (#85718) next »