Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85730 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88751 invoked from network); 3 Apr 2015 22:08:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Apr 2015 22:08:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.213.53 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.213.53 mail-yh0-f53.google.com Received: from [209.85.213.53] ([209.85.213.53:36041] helo=mail-yh0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6A/98-23347-15F0F155 for ; Fri, 03 Apr 2015 17:08:18 -0500 Received: by yhme10 with SMTP id e10so6782851yhm.3 for ; Fri, 03 Apr 2015 15:08:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=KD7hDoB5nPyNI98nq06mVILCMi39tmc6t7lhM7mfau4=; b=HWGAxzMylHqXpBLHAM/CzVu3uwTKNLNGOhIrSd4jsMWxS7E9HFn+2vzV7dfcGPm5yS IMLPVBcfwTmWTWFkQMqblHTMf5xaKYf60dzohK6YBhrLs3zSoHUro0SEl1vUur41daDI MVEYzEd8koR9guvv90VIKo+snR9qhoRYmoVcS7WzPd0sUKUdocsgDX/ylcsPas4umgC4 p6Mr0Qalgul1W2b7nrQmlNqmxvYRYoC9m4WNgfTrE29mHL2T7kKgbGwzg4UF7n772Bsv kTRT6LsZzYxLmCw/xdKZuNT/nQe6pwpXrOYojUU4NIiFxooycJ8Po+L6k+FiRORNYQm+ spaQ== X-Gm-Message-State: ALoCoQnJz4/ty9E+egSMkaKWMxTwkktmUXQD57w6JiZG/437LlhQect6UyNHYjD6iOZ0nvBQaJSVPQyPRbzcs97VFFEBL+dCrgX5aPOr5DM4t8qyHLTvS8cEPf94IkMnB+uIQFAwxR0HyvZw+g/UYAUID3hVE7EXtA== MIME-Version: 1.0 X-Received: by 10.52.160.232 with SMTP id xn8mr2493888vdb.78.1428098894419; Fri, 03 Apr 2015 15:08:14 -0700 (PDT) Received: by 10.52.248.36 with HTTP; Fri, 3 Apr 2015 15:08:14 -0700 (PDT) Received: by 10.52.248.36 with HTTP; Fri, 3 Apr 2015 15:08:14 -0700 (PDT) In-Reply-To: References: <33BCE1D0-BA6D-464C-B23D-69AF71356111@ajf.me> <3932E76B-DC75-40CD-8B1A-B84F387707CC@ajf.me> Date: Sat, 4 Apr 2015 01:08:14 +0300 Message-ID: To: Nikita Popov Cc: PHP Internals , Andrea Faulds Content-Type: multipart/alternative; boundary=089e0160d2104e72580512d92f25 Subject: Re: Fix division by zero to throw exception From: dmitry@zend.com (Dmitry Stogov) --089e0160d2104e72580512d92f25 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Apr 4, 2015 12:34 AM, "Nikita Popov" wrote: > > On Fri, Apr 3, 2015 at 11:13 PM, Dmitry Stogov wrote: >> >> >> >> >> On Fri, Apr 3, 2015 at 11:59 PM, Andrea Faulds wrote: >>> >>> Hi, >>> >>> > On 3 Apr 2015, at 20:46, Dmitry Stogov wrote: >>> > >>> > May be you'll also suggest something regarding bitwise shifts with negative offset? >>> > Allowing negative offsets using opposite directions would fix inconsistency, but I remember, you didn't like it. >>> > May be keep WARNING (Bit shift by negative number) and then perform shift in another direction? >>> > + disable negative shifts at compile-time. >>> >>> I don=E2=80=99t think opposite-direction shifts would work well for a f= ew reasons. I don=E2=80=99t believe this is normal behaviour in other language= s, for one. Another issue is that << and >> are not actually opposites, they have different behaviour with respect to signs, so there=E2=80=99d be ambiguity = as to what $x << -$y means (is it the same as $x >> $y, or does it deal differently with signs?). Negative shifts being used are usually the result of mistakes, as well, so you want to inform the user. >>> >>> The main problem, though, is that we previously did something different if the shift is negative. Having it now produce a warning, means you=E2=80= =99ll see error messages when you run existing code. But shifting in the opposite direction might change the behaviour of existing code silently >>> >>> I think the most sensible solution would be to make negative shifts produce an exception, since they=E2=80=99re really an error, an unsupported operation. I made them be a warning + return FALSE just because it matched division. But that=E2=80=99s not ideal and I=E2=80=99d be fine if it was re= placed. >> >> >> OK. Exception is fine. >> >> So the summary: >> >> 1) division by zero produces a warning and +/-INF IS_DOUBLE. Compile-time evaluation is disabled. >> >> 2) Negative shift produces Exception.Compile-time evaluation is disabled= . >> >> 3) Modulo by zero produces Exception.Compile-time evaluation is disabled= . >> >> Everything right? > > > Don't think we need to disable compile-time evaluation for 2) and 3). It'll just end up being a compile error in that case. I think if you have 1 % 0 occurring in your code literally, it's better to have the compile fail rather than getting (or not getting) a runtime exception. This is even easier. Andrea, what do you think? Thanks. Dmitry. > > Nikita > --089e0160d2104e72580512d92f25--