Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113082 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 67186 invoked from network); 4 Feb 2021 19:38:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2021 19:38:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B9792180089 for ; Thu, 4 Feb 2021 11:21:59 -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=-1.2 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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:21:58 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4640A5C00AD for ; Thu, 4 Feb 2021 14:21:58 -0500 (EST) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Thu, 04 Feb 2021 14:21:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=oW6BAB wKLGirLcXrUMvu4Dk4atNU4XeyCgCbUeqi7fs=; b=USpbLywQ0hApvzJU8j2LVI k6uGqxTDln0ZOxfuVNPHuxTM2Ar1l2Pkq9O7300pA7B3mukCUGop7gPcDNNMQjf0 Sz8nVqWgKS2oZwlHHAymW7A9+SsYMjophMsBwlp2J6997fO3hHn6qBXD9zHVCgap 3YzQ1usXVu10GX/YBtgMIGtXdqyHrabkIg5MNebVnq4ZyXz1VI3/saeuBqlwQtjE aQkyoBfjX4eZot5fEKqtb/GZD1B46tQHx3b284wK2IqTE8/Ho0iFdHxGXoTftpbh cTmMSXcbCTxRccVDmiloK9GYjazBYlTw6LpprBv5CjRAWujVxulxToGYC22Dbtzw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrgeeggdduudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id E9B473A0074; Thu, 4 Feb 2021 14:21:57 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-93-gef6c4048e6-fm-20210128.002-gef6c4048 Mime-Version: 1.0 Message-ID: <49613676-f71b-49ba-88d5-3c5d5bcd998c@www.fastmail.com> In-Reply-To: References: Date: Thu, 04 Feb 2021 13:21:36 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Warning for implicit float to int conversions From: larry@garfieldtech.com ("Larry Garfield") 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