Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83135 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74380 invoked from network); 18 Feb 2015 23:21:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 23:21:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:40307] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/00-08593-66E15E45 for ; Wed, 18 Feb 2015 18:21:11 -0500 Received: by labgd6 with SMTP id gd6so4471466lab.7 for ; Wed, 18 Feb 2015 15:21:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=eYjy+FXCwp3eIvJxXKomhHrAXOZTen21fBoXKsETLLk=; b=aA+stAKq3owdlgd0FXinSoJfREuIh0UgbvCnek/CwR/3Bqhz6fuUqfz06lliP+KdoI eaA46B0pjRtPQkCs6EWmAiJ6ny3/WrSBbsoh49TURbtp4yaYlVpsE160bjXX6NPpw1HL eCmYAxnpfrXZD/zCLftrVz1Fh2Wq66oJwI+YrbfoTU2fDNQX8Py0v2RwohHxq6UnL63k ZytVkGc4+eYs6xm/qXpcR4v3kVM/yHTnQbB/FPWiybtsH2tSD5Qtb/tis3qtf8OrFlYt gUL1ldf01zWZp5jcLAwa/PVR24A11r40UpO2/sZRI5YtbELwxjRBBPiaysOUdrKr9FYE iXbg== MIME-Version: 1.0 X-Received: by 10.112.92.204 with SMTP id co12mr1479060lbb.43.1424301666920; Wed, 18 Feb 2015 15:21:06 -0800 (PST) Received: by 10.25.43.9 with HTTP; Wed, 18 Feb 2015 15:21:06 -0800 (PST) In-Reply-To: <54E51B9E.1060201@gmx.de> References: <54E51B9E.1060201@gmx.de> Date: Wed, 18 Feb 2015 18:21:06 -0500 Message-ID: To: Christoph Becker Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [RFC-Discuss] Scalar Type Declarations v0.5 From: ircmaxell@gmail.com (Anthony Ferrara) Christoph, On Wed, Feb 18, 2015 at 6:09 PM, Christoph Becker wrote: > Anthony Ferrara wrote: > >> 3. int typed variables can resolve a parameter type of float So >> calling requiresAFloat(10) will work even in strict mode. > > Have you considered the overflow behavior of ints resulting in a float? > For instance, the following code would produce E_RECOVERABLE_ERROR, AIUI: > > > declare(strict_types=1); > > function foo(int a, int b) { > bar(a * b); > } > > function bar(int n) { > } > > foo(10000000000, 10000000000); > > It seems to me that this behavior is hard to deal with generally for > programmers as well as static analyzers. Andreas' bigint RFC[1] would > solve that issue, but it has been withdrawn, and AFAIK nobody is working > on it. OTOH, bigint would make the widening from int to float > potentially even more lossy (i.e. inaccurate) than it is now (64bit ints > vs. IEEE 754 doubles). > > IIRC, Pascal does not promote int to float on overflow, but rather > discards the high bits (unless overflow checking is enabled; available > only in some "newer" dialects). I don't know how Java handles this > case, but I assume there's no promotion to float either. > > [1] > That is a very good point. We had discussed that a while ago, but it hasn't come up in a while here. I've added a section in the RFC on it: https://wiki.php.net/rfc/scalar_type_hints_v5#integer_overflow_to_float_behavior Basically, I don't see any sane alternative but to have it cause an error at runtime. It's not precision loss, it's magnitude loss. The only other thing I can think of is to have the operators not promote in strict mode, but that's even worse since now you're clamping and not even giving the ability to detect it. I don't think in practice it will be a huge issue, but even if it comes up, it'll at least error sanely... Thanks Anthony