加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

有人能给我一个很好的理由说明为什么php中的断言行为方式呢?

发布时间:2020-12-13 21:59:30 所属栏目:PHP教程 来源:网络整理
导读:PHP的断言语句与大多数其他语言的行为不同. 断言(‘return false’);实际上计算字符串然后断言其结果(false). 它不是将参数与true进行比较,而是通过检查参数的额外步骤,如果是评估它的字符串,则执行比较. 确实非常奇怪. 我的问题不是理解行为,我的问题是出现
PHP的断言语句与大多数其他语言的行为不同.

断言(‘return false’);实际上计算字符串然后断言其结果(false).

它不是将参数与true进行比较,而是通过检查参数的额外步骤,如果是评估它的字符串,则执行比较.

确实非常奇怪.

我的问题不是理解行为,我的问题是出现这种行为的正当理由,尤其是.因为你现在必须做额外的思维工作……“这会评估成一个字符串吗?”

解决方法

The advantages of a string assertion are less overhead when assertion checking is off and messages containing the assertion expression when an assertion fails. This means that if you pass a boolean condition as assertion this condition will not show up as parameter to the assertion function which you may have defined with the assert_options() function,the condition is converted to a string before calling that handler function,and the boolean FALSE is converted as the empty string.

从http://www.php.net/manual/en/function.assert.php

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读