Re: Fix division by zero to throw exception

From: Date: Fri, 03 Apr 2015 21:15:43 +0000
Subject: Re: Fix division by zero to throw exception
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-85728@lists.php.net to get a copy of this message
On Sat, Apr 4, 2015 at 12:04 AM, Andrea Faulds <ajf@ajf.me> wrote: > 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. > Cool :) 4) fix intdiv() to throw exception. Thanks. Dmitry, > > Thanks. > > -- > Andrea Faulds > http://ajf.me/ > > > > >

« previous php.internals (#85728) next »