Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113083 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69489 invoked from network); 4 Feb 2021 19:59:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2021 19:59:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1A9901804DD for ; Thu, 4 Feb 2021 11:43:25 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Feb 2021 11:43:24 -0800 (PST) Received: by mail-ot1-f54.google.com with SMTP id s107so4585428otb.8 for ; Thu, 04 Feb 2021 11:43:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=XdW0SNVJrtd10HsTNUlU1A0egqg3sZodzbX5AUChqxM=; b=RLPkv/UmB98qxE0ZhWmYrFqBh+vXCufmPggSQ1zcqN8ljnCP4g4LJHLl1VIxeVAEld +vWWYGaFCuEBHQbhFVOJ+/I6Eb6bYEu10nqBVeYP5de0ZWkrkQ8ODYt8s758CuAWdsq+ WRCQToWhd1NmWp238p3z/ZpYvr2oylasaYkrIJOOTM9fIxGg4oW5TIc8o2/EV/VUD/U2 mb3fSWW1z8l3NkLjo7NsBTyJKKlBl6bwBVZX6vrOzH/Z3SM5G1771KVOuL1bI4IGmMsF X2vJIrE1n2SLu6oRnSdaJKo0dJ0HcXnPTucXj99jMJx/iAlUkYaXXKKzYTrdGq6RZTM1 R/NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=XdW0SNVJrtd10HsTNUlU1A0egqg3sZodzbX5AUChqxM=; b=VOc4K821StKMYXHZuk96Q8nWiRfbK6SLcWP4NyN12os4sZMWzyzhzi1TH7syy8D2WG qx9zz4xAYktnRY6+7loCvfsy6uKFFMHKD0OMyea9Fib4vYh3ik6eMjFCm73u0M64AGA0 IiVSx0LwKWIVewbWFrVeRe+jRQ3JovoROhK2/15nX1shUAEt+2U9ACcsTlH0NlBbHlDu ym/y/7ele+radpRgqbsymoWrr26XW6NTiL+EXzmooLorOs1Qhuo6KJUmY2EbwYxQHoTs gnc7fQOZYHS1liIojd7R+h4zZWKzuPP5pFvTpzqPW8zBB02EyAXNpolb/oMPNtbofhcU +8GQ== X-Gm-Message-State: AOAM5315Zf+xBHLiU5j6pDAH1aNuuZYX+kJdIzW7gLva/sXvs62I74Lg OH2eTiJxFYyIUITXj66tvpYyzSTejYZ+GSG46e0wk0XhMzVGRA== X-Google-Smtp-Source: ABdhPJzG/5AfN4SWiwDKPpH4FF3XOxv7UcRPQmNNL8odKnLsTu8dgR62z5VRkenR8Iyri6zPIR1yKapS00qtpTDDvTo= X-Received: by 2002:a9d:7503:: with SMTP id r3mr788483otk.236.1612467800746; Thu, 04 Feb 2021 11:43:20 -0800 (PST) MIME-Version: 1.0 References: <49613676-f71b-49ba-88d5-3c5d5bcd998c@www.fastmail.com> In-Reply-To: <49613676-f71b-49ba-88d5-3c5d5bcd998c@www.fastmail.com> Date: Thu, 4 Feb 2021 19:43:09 +0000 Message-ID: To: php internals Content-Type: multipart/alternative; boundary="00000000000079ad9205ba87ea96" Subject: Re: [PHP-DEV] [RFC] Warning for implicit float to int conversions From: davidgebler@gmail.com (David Gebler) --00000000000079ad9205ba87ea96 Content-Type: text/plain; charset="UTF-8" > Except that example is ambiguous. Specifically, which is more logical, to truncate it to 3 or round it up to 4? It probably depends heavily on your context. Implicitly doing one or the other can result in surprises. I disagree this is ambiguous. The integral portion of a float is what it is, any notion of rounding it up is no more relevant here than multiplying by it 20, calculating it's sin value or anything else you can do with a number. These are operations you explicitly choose to perform on a scalar. On Thu, Feb 4, 2021 at 7:22 PM Larry Garfield wrote: > On Thu, Feb 4, 2021, at 12:06 PM, David Gebler wrote: > > If this were to be done, my gut feeling is a notice would be preferable > to > > a warning, particularly as there must be many scripts which would > suddenly > > start churning out warnings for this proposed change which might/probably > > ignore lower error levels and emitting a warning for a previously common > > script behaviour is quite a significant backwards incompatible change. > > > > The bit which makes me more nervous about the proposed change is your > > rationale that implicit float to int conversion dropping the fractional > > portion means there is "no way to know if the data provided is > erroneous". > > > > I get the idea behind your proposal, but equally I'm not convinced this > is > > comparable to numeric vs non-numeric or malformed/partially numeric > > strings. There isn't any value of the string "foobar" which makes sense > as > > an integer. But there is a value for a float which makes sense as an > > integer; the integral part. In the float 3.81232 the integral portion 3 > is > > completely unambiguous. It's not like it would make just as much sense to > > interpret it as any other arbitrary integer value. > > Except that example is ambiguous. Specifically, which is more logical, to > truncate it to 3 or round it up to 4? It probably depends heavily on your > context. Implicitly doing one or the other can result in surprises. > > > My main concern is if you're casting floats to ints and the floats are > usually ints anyway, and so no error, you may not even realize the error > remains for a long time until you suddenly start getting a warning if your > incoming data shifts. I have no idea how common that pattern is in > practice, though. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000079ad9205ba87ea96--