Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104520 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48050 invoked from network); 26 Feb 2019 16:18:34 -0000 Received: from unknown (HELO mail-vk1-f194.google.com) (209.85.221.194) by pb1.pair.com with SMTP; 26 Feb 2019 16:18:34 -0000 Received: by mail-vk1-f194.google.com with SMTP id x140so2945829vke.5 for ; Tue, 26 Feb 2019 05:04:57 -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 :cc; bh=AFuAkvcHIhVT4vSbuFrPCuDHdgmR1j7bzVVm9e7cZyo=; b=E5walUctPg0Ecso6/aWSI/9s9TghdFKneGlZg6peDQfklXtoEzqt6sgR1lXHSAh8pH KQeYgcOwZStMyplp3G8iUrBwSu9psJffMy7NOzS0N/l+I1Qtd5TYsNJheyFyZQ4vu5fW ZkVFgb1AsYmO+8X7lY95sOvJ0XG/seOGKN+awtHU0jiW8qUBCCQGZmNqe11S7V5Y0IWF 69V3Eetc6IS16DMgUhSg8rdQ5YlF56cKvimfwlCh6D13lepcYPLRYTzEj9D3r8xSNF1X qw+TxamKnaEcSddQbZ73U6G/vIEvuMCp/QBUcOhdpqBBsn/9oNcOg1j/49vheVTKoUEZ EZrg== 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:cc; bh=AFuAkvcHIhVT4vSbuFrPCuDHdgmR1j7bzVVm9e7cZyo=; b=ndC3NHOdPRdjtN3xCAGVeqplFw/JFAneXUj4j0H9wfZ1FnGBpPl3+KvAEvg1G7B5z1 cvkJAryExTsKqrf1jcgbOMpWKWZgmkstHo3Yqc1Sqja2whhqEQ5bm4kBZy6vB+CazBvO QBGxJl+falVG47CwEOtqgnJY3tPxTfC2t+xrXbZxeca2GOF7rEt/xHtj+OXN5VPwdgB7 7hZ3qbyp8wC3s9kIelikXiDT7YtQ4NabU/eWypa5bht65MSC5Czw+QSOHqzzSjPHDvB+ CorN7RJjEERXKn7ykRC6dB/zxXxHVQMQgvC8f6rRYzivBoraTNAKV+vGkvYXzfYNkecu x9Jg== X-Gm-Message-State: AHQUAuYW9Z/D/d/Ewq1pZG1d89GpT7n+f34f/L0uf2VNSaxDUL5/eyUS YxewtIpzyjTYxR065itPSjhOO/24SXjb5goS620= X-Google-Smtp-Source: AHgI3IYbcerZ3jqdfIBX61VOmNlQs32AT9pK03a9zQ59zhsoZXfYdmQpIlcXRT2yg8zQiIeViTDBETEPipXRdnxYRWc= X-Received: by 2002:a1f:17c2:: with SMTP id 185mr12365153vkx.7.1551186297164; Tue, 26 Feb 2019 05:04:57 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 26 Feb 2019 14:04:44 +0100 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000039166d0582cbb4f4" Subject: Re: [PHP-DEV] [RFC] Saner string to number comparisons From: george.banyard@gmail.com ("G. P. B.") --00000000000039166d0582cbb4f4 Content-Type: text/plain; charset="UTF-8" On Tue, 26 Feb 2019 at 13:27, Nikita Popov wrote: > Hi internals, > > I think it is well known that == in PHP is a pretty big footgun. It doesn't > have to be. I think that type juggling comparisons in a language like PHP > have some merit, it's just that the particular semantics of == in PHP make > it so dangerous. The biggest WTF factor is probably that 0 == "foobar" > returns true. > > I'd like to bring forward an RFC for PHP 8 to change the semantics of == > and other non-strict comparisons, when used between a number and a string: > > https://wiki.php.net/rfc/string_to_number_comparison > > The tl;dr is that if you compare a number and a numeric string, they'll be > compared as numbers. Otherwise, the number is converted into a string and > they'll be compared as strings. > > This is a very significant change -- not so much because the actual BC > breakage is expected to be particularly large, but because it is a silent > change in core language semantics, which makes it hard to determine whether > or not code is affected by the change. There are things we can do about > this, for example the RFC suggests that we might want to have a transition > mode where we perform the comparison using both the old and the new > semantics and warn if the result differs. > > I think we should give serious consideration to making such a change. I'd > be interested to hear whether other people think this is worthwhile, and > how we could go about doing it, while minimizing breakage. > > Regards, > Nikita > I am in favor of this change however I do think having the Trailing Whitespaces numerics RFC would be better for this change as I do agree with you that IMHO 42 == "42 " should return true. I'm also not sure if you maybe should point this out sooner but as it is currently seems fine to me. However small nitpick on your precision section $float = 1.75; ini_set ('precision', 14); // Defaultvar_dump ($float < "1.75abc");// Behaves likevar_dump ("1.75" < "1.75abc"); // true is wrong because var_dump($float < "1.75abc"); returns false: https://3v4l.org/G56Vj I think you meant to use the <= comparison operator maybe? Also the NAN behavior is a bit surprising (to me atleast) but it does follow the IEEE-754 However I don't really understand why it always returns 1 with the TIE operator. And finally as to how to do the transition I don't really have a strong opinion about it. An INI setting seems like this behavior is going to be supported for a long time. But it doesn't seem like its possible to throw deprecation notices to alert of this change. Best regards George P. Banyard --00000000000039166d0582cbb4f4--