Re: Fix division by zero to throw exception

From: Date: Fri, 03 Apr 2015 21:04:48 +0000
Subject: Re: Fix division by zero to throw exception
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-85726@lists.php.net to get a copy of this message
Hi, > On 3 Apr 2015, at 21:34, Dmitry Stogov <dmitry@zend.com> wrote: > > 3) One more problem is modulo :( > > $ sapi/cli/php -n -r "var_dump(1 % 0);" > > Warning: Division by zero in Command line code on line 1 > bool(false) Hmm, modulo is a more difficult one. Since it’s an integer-only operation in PHP, producing INF doesn’t make sense. It also doesn’t make sense mathematically. I think the most sensible thing to do here would be to throw an exception. On the same note, the new function intdiv() is the counterpart to % for obtaining the quotient (% produces the remainder). It currently does the same thing as % and / division and produces FALSE with a warning. If % is changed, intdiv() should be too, because they are the same operation, just returning different parts of the result. An exception being produced by both would seem reasonable. Thanks. -- Andrea Faulds http://ajf.me/

« previous php.internals (#85726) next »