变量赋值的结果与函数的返回值不同:
function test() {
return !true
or !true
or !count(4)
or (
new stdClass() and true
);
}
$result = !true
or !true
or !count(4)
or (
new stdClass() and true
);
echo (int)$result . PHP_EOL; // 0
echo (int)test() . PHP_EOL; // 1
这是由于操作符优先级。
赋值操作优先级高于and
/or
。
第一个等于:
function test() {
return (!true
or !true
or !count(4)
or (
new stdClass() and true
));
}
而第二个等于:
($result = !true)
or !true
or !count(4)
or (
new stdClass() and true
);
用&&
/||
代替and
/or
,结果是一样的