PHP运算符优先级错误? [英] PHP operator precedence bug?

查看:171
本文介绍了PHP运算符优先级错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果:

var_dump(null != $a = 15);
var_dump($a);

是:

bool(true)
int(15)

不触发错误?
由于!= (不等于运算符)的优先级高于 = code> $ a 应该与 null 比较?

Why is this script not triggering an error? Since != (not equal operator) has a higher precedence than = (assignment operator), $a should be compared to null first?

推荐答案

我能找到的唯一原因是文档说这仍然是合法的: http://php.net/manual/en/language.operators.precedence.php#example-129

The only reason I can find is that the documentation says that this is still legal: http://php.net/manual/en/language.operators.precedence.php#example-129

这似乎是上面表格中显示的例外。

It seems to be an exception to what is shown in the table above.

这篇关于PHP运算符优先级错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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