Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96609 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43184 invoked from network); 25 Oct 2016 15:22:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Oct 2016 15:22:34 -0000 X-Host-Fingerprint: 2.124.144.170 unknown Received: from [2.124.144.170] ([2.124.144.170:15714] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/13-24108-B987F085 for ; Tue, 25 Oct 2016 11:22:19 -0400 Message-ID: <0C.13.24108.B987F085@pb1.pair.com> To: internals@lists.php.net References: <2cab4219-5128-7493-c604-5772534743ea@mabe.berlin> <2A.9D.28528.43F0E085@pb1.pair.com> <3b5cea00-2d80-8f96-e797-abb3ce409e6c@mabe.berlin> Date: Tue, 25 Oct 2016 16:21:37 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40 MIME-Version: 1.0 In-Reply-To: <3b5cea00-2d80-8f96-e797-abb3ce409e6c@mabe.berlin> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 2.124.144.170 Subject: Re: [PHP-DEV] strtod and NaN vs. zero From: ajf@ajf.me (Andrea Faulds) Hi, Marc Bennewitz wrote: > It's totally true that on casting non numeric string to integer will > result in 0 but that's a different type even if it's also a numeric type. > > From my understanding PHP tries to cast from one type to another by > loosing as less information as possible. In this case I see a non > numeric string that gets casted to a float will loose exactly this > information that it's "Not a Number" where it would be possible to keep > this information. On casting this to int there is of course no > possibility to keep it but I don't see where it's inconsistent as it's a > different type used for different use-cases. (int) and (float) are lossy and have always been so. If you want PHP to complain when you give it something non-numeric, rather than coerce to 0, there are alternatives. > Having mathematical operations with non numeric strings should result in > the same behavior as NaN will result in NaN which makes sense and I > don't see where it will throw lots on WARNINGS or TypeErrors as it's > still a float. Because previously it would be an integer. "foo" + "bar" currently gives an integer 0. Now it would give you a float NaN. That has potential knock-on effects. Thanks. -- Andrea Faulds https://ajf.me/