Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104532 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59942 invoked from network); 27 Feb 2019 17:14:16 -0000 Received: from unknown (HELO mail-wr1-f51.google.com) (209.85.221.51) by pb1.pair.com with SMTP; 27 Feb 2019 17:14:16 -0000 Received: by mail-wr1-f51.google.com with SMTP id d17so18035078wre.10 for ; Wed, 27 Feb 2019 06:00:55 -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=Xg8XoAn79tBRs8omnnJ5T1WFDT99GTekD797C7Z27ns=; b=heZ/wHpD7OxXsGUIoejuPHsg0NnbPFOazhiM4mLMTmWa8W2gSb9AiHl0GuTiHuzNmo AeV6KNFWRHhBEngTWgBmqvdiPjNSlUFFWCtu4zB7orpJ7MU4RYUn5CYYYn8ka2zlDyaL hfXQ+5C33xcT9nVbPTWofrWEuTQ4NCaV+10yCUGhIaUVVkBVhlUtQ2tdTOK+LKeiR0Mk EgnMH2tu8onqWweKKnGWx8W1yag+cfX2mp9bs5KYy5LhGlL7M2xLE9j7Ug/7uHh9L7kN Otu1eI9z2tTlQrZ13dtluA7+PtajN/nQX71da8qu9HrKjETq7KyfU1xl4NnmEKwx4lvw tsyw== 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=Xg8XoAn79tBRs8omnnJ5T1WFDT99GTekD797C7Z27ns=; b=Cn9HXyY8SmUIJ0BkrxnnkTAkMl9e5SdhBKqX++8f4DtkWE8fhfyBu6Iwza/HOTw4Yn JLeQ8XxUMN/OIYu89k2zwPfRRCJ4a2vLIYJX/dYfgLNp2Fo5ES6ebwy3YmtU1Zrgx0Bj N7MDlOxOmIUN5gUBa5ELSpmABgQJt8U0103+n6xCfx3QqKkKedxI3vGmw9bb/N+XR8VM dd3eS/zwTb1a6XBU5+Cp/EwUV31xqc750uGJODZ55adz0rXFuLLxFGq9hI77MEYzn41J uN3acWSMemRw//lpzsFFP2lPtP2tkFR63olTCV4SbMYdGDSt2VEf1uNGKPCyVeZFe83b kEhA== X-Gm-Message-State: APjAAAWvQGHzBVqMo3cfMo9Xv43z2AvdGiSDP2ZPpbM0Fp/lqmHIUhUL s9oD5QplFSHY10yHkQGPPJjqwcA9JDTGmVWNehI= X-Google-Smtp-Source: APXvYqz/BqVpWPpHhFcR+I2f1S/v4nVqEYg3hZRvYv59ACedNS0yxKkAJ734yCcTCAeSwb5DSYrDpPntWZ6347FlprQ= X-Received: by 2002:adf:f78e:: with SMTP id q14mr2804987wrp.227.1551276054201; Wed, 27 Feb 2019 06:00:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 27 Feb 2019 11:00:42 -0300 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000028cb260582e09abf" Subject: Re: [PHP-DEV] [RFC] Saner string to number comparisons From: carusogabriel34@gmail.com (Gabriel Caruso) --00000000000028cb260582e09abf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em ter, 26 de fev de 2019 =C3=A0s 09:28, Nikita Popov escreveu: > Hi internals, > > I think it is well known that =3D=3D in PHP is a pretty big footgun. It d= oesn'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 =3D=3D in PHP= make > it so dangerous. The biggest WTF factor is probably that 0 =3D=3D "foobar= " > returns true. > > I'd like to bring forward an RFC for PHP 8 to change the semantics of =3D= =3D > 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 b= e > 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 wheth= er > 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 transitio= n > 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 > Hi Nikita, There's only one case that I'm not sure about > Comparison | Before | After > ------------------------------ > 0 =3D=3D "" | true | false I know that a cast of am empty and non-empty string results into 0 ( https://3v4l.org/W0P3Z), but still, not sure about this one in specific. Best, --=20 Gabriel Caruso --00000000000028cb260582e09abf--