Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104519 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38180 invoked from network); 26 Feb 2019 15:41:19 -0000 Received: from unknown (HELO mail-io1-f42.google.com) (209.85.166.42) by pb1.pair.com with SMTP; 26 Feb 2019 15:41:19 -0000 Received: by mail-io1-f42.google.com with SMTP id p17so10300989iol.7 for ; Tue, 26 Feb 2019 04:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=/0IYKQjx8deqkXvTTUDq0mRXAAY2/4XCf+dZ0t+ANlE=; b=RobbpPmoqki3vhboqzJOKiTPhEaewxF/KXHThOkjCy9Dflt4YKhZ1H2EDifLC9NVmq nw5TAnAZKUKS0B/2IUKWa7zDWrlMg739NBldUeYYvW9lDiTV+3mQNqh2ax5pGw885YxS NsrT9Px1gFw9y7vqg6IqW3ntqmb/XTjw+AKLOZCVdBgWTuNoPHuTk/MypeaHxH5vIZu1 RKjR+Vq5H423rvvuaLbHBNORfopirVk21x+gx5oigMSyaQvwp5eBELd9SKQY+YH+H7br 44mttVeybAaesDpcZaYDQ+5eJuuN8Nvw8Wsb6jPtofV7JrYBEW9KrztAdjVDjhBOMs9y kv5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=/0IYKQjx8deqkXvTTUDq0mRXAAY2/4XCf+dZ0t+ANlE=; b=FNSWZeFOOiKa6LO/SA3ShsXujeXBkkUASot728GlzVuWowTXUAXGAE4Dcb5eb+H++d VdaHkuv1u1IMrJ+8iVqfLLAVacEt/vz/9CkygX0//N9V6dBUNjbCrx3I1KNsz6GSI13u kT+PRe6KZMsUQUoYeubzJ6SVFsAfZJLlGBCeqLzL2lqYr0tYOSBxVVTHCFMuKlsGXN/h nl0NCNwFh4m2TtzG0RktqV8vFD2qOWEb40G2bOP9JylF6X29K6sP67ZrwzUKm3B0UQ4b pWnBz7Ah8ePVf24K98QIGKrrsNNy8s3U3W/oVJEOphirghOzWVpYL20C9zxmBJqwhE/C 7KXA== X-Gm-Message-State: AHQUAuYNGIhdQ9EfeDZX1Onv0ZQ0IpUlZi1HdPHEpSBcyBgSlR8zFfTg siYNq4GgUwcjbuRY3j5xFZYGdtRcprZTLrI/scx+YdV+ X-Google-Smtp-Source: AHgI3IbfNcXvUK+csfwzF9Kg6Gaojl5dDQvrPlEQ+/sjRCR6rL1HjEqeczjZdUrkjvD5RN/AR1WoqxirDl7aX2axviA= X-Received: by 2002:a5e:c906:: with SMTP id z6mr11955249iol.47.1551184061195; Tue, 26 Feb 2019 04:27:41 -0800 (PST) MIME-Version: 1.0 Date: Tue, 26 Feb 2019 13:27:23 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000f2e9140582cb2eb1" Subject: [RFC] Saner string to number comparisons From: nikita.ppv@gmail.com (Nikita Popov) --000000000000f2e9140582cb2eb1 Content-Type: text/plain; charset="UTF-8" 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 --000000000000f2e9140582cb2eb1--