Re: [RFC] Strict operators directive
| From: | Rowan Collins | Date: | Wed, 26 Jun 2019 12:08:10 +0000 |
| Subject: | Re: [RFC] Strict operators directive | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106074@lists.php.net to get a copy of this message | ||
On Wed, 26 Jun 2019 at 12:46, Benjamin Morel <benjamin.morel@gmail.com>
wrote:
> This makes sense for "<", "<=", ">", ">=",
> but what about "==" and "!="?
>
> Currently, "11" == "11.0"; what would this yield under the new proposal?
>
> - leave it as is: return true in this case => contradicts the whole purpose
> of the new proposal
> - throw a TypeError when performing the above comparison => not acceptable
> either I guess; every language allows == and != on strings, forcing to use
> strict comparison operators is a bit weird here.
> - change the semantics to return false when both operands are strings, and
> don't match => not acceptable to you as you cannot know what a line of code
> does without checking the header
>
Given that we already have === and !==, could the strict mode simply throw
an error for *any* use of the non-strict == and != versions?
declare(strict_operators=1);
var_dump( "11" == "11.0" ); # TypeError: "Cannot use non-strict equality
operator in strict operator mode."
var_dump( "11" === "11.0"); # bool(false)
I'm not sure whether I like the idea or not, but I thought I'd throw it out
there as a possibility.
Regards,
--
Rowan Collins
[IMSoP]