“!==”之间的差异和“==!”。 [英] Difference between "!==" and "==!"

查看:186
本文介绍了“!==”之间的差异和“==!”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我在修改别人写的PHP代码时,偶然发现了这个问题。我很困惑,一个简单的比较( if($ var ==!))没有按预期工作。经过一些测试,我意识到无论谁编写的代码使用 ==!而不是作为比较运算符。我从来没有见过 ==!在任何语言,所以我想知道这个代码甚至可以工作,并做了一些测试:

Yesterday I stumbled over this when I modified PHP code written by someone else. I was baffled that a simple comparison (if ($var ==! " ")) didn't work as expected. After some testing I realized that whoever wrote that code used ==! instead of !== as comparison operator. I've never seen ==! in any language so I wondered how the hell this code could even work and did some testing:

<?php
echo "int\n";
echo "1 !== 0: "; var_dump(1 !== 0);
echo "1 !== 1: "; var_dump(1 !== 1);
echo "1 ==! 0: "; var_dump(1 ==! 0);
echo "1 ==! 1: "; var_dump(1 ==! 1);
echo "bool\n";
echo "true !== false: "; var_dump(true !== false);
echo "true !== true: "; var_dump(true !== true);
echo "true ==! false: "; var_dump(true ==! false);
echo "true ==! true: "; var_dump(true ==! true);
echo "string\n";
echo '"a" !== " ": '; var_dump("a" !== " ");
echo '"a" !== "a": '; var_dump("a" !== "a");
echo '"a" ==! " ": '; var_dump("a" ==! " ");
echo '"a" ==! "a": '; var_dump("a" ==! "a");
?>

这将产生以下输出:

int
1 !== 0: bool(true)
1 !== 1: bool(false)
1 ==! 0: bool(true)
1 ==! 1: bool(false)
bool
true !== false: bool(true)
true !== true: bool(false)
true ==! false: bool(true)
true ==! true: bool(false)
string
"a" !== " ": bool(true)
"a" !== "a": bool(false)
"a" ==! " ": bool(false)
"a" ==! "a": bool(false)

运算符似乎适用于布尔和整数变量,字符串。我在PHP文档或任何搜索引擎上找不到 ==!(尝试Google,Bing,DuckDuckGo,但我怀疑他们试图解释它的搜索文字字符串)。

The operator seems to work for boolean and integer variables, but not for strings. I can't find ==! in the PHP documentation or anything about it on any search engine (tried Google, Bing, DuckDuckGo, but I suspect they try to interpret it instead of searching for the literal string). Has anybody seen this before and can shed any light on this behavior?

推荐答案

不同之处在于没有操作符 ==!

The difference is that there is no operator ==!.

此表达式:

$a ==! $b

基本上与此相同:

$a == (!$b)

这篇关于“!==”之间的差异和“==!”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆