断言不能在php中工作.很简单.我究竟做错了什么?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了断言不能在php中工作.很简单.我究竟做错了什么?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这就像断言甚至没有被调用.我很迷惑.

版本

:~/code/x/test$PHP -v
PHP 7.0.11-1+deb.sury.org~Xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0,Copyright (c) 1998-2016 Zend TechnoLOGies
    wITh Zend Opcache v7.0.11-1+deb.sury.org~xenial+1,Copyright (c) 1999-2016,by Zend Technologies

剧本

:~/code/x/test$cat x.PHP
<?PHP

PRint ("Hello\n");

assert_options(ASSERT_ACTIVE,true);
assert_options(ASSERT_BaiL,true);

assert(false);
assert(true);

print ("Bye\n");

当我跑它

:~/code/x/test$PHP x.PHP
Hello
Bye

我原以为程序会以异常终止.我疯了吗?

谢谢RiggsFolly.

看起来像断言在7.0的开箱即用.在我的PHP.ini文件中,zend.assertions设置为-1,这意味着它们被忽略.我已将设置更改为1.

[Assertion]
; Switch whether to compile assertions at all (to have no overhead at run-time)
; -1: Do not compile at all
;  0: Jump over assertion at run-time
;  1: Execute assertions
; Changing From or to a negative value is only possible in PHP.ini! (For turning assertions on and off at run-time,see assert.active,when zend.assertions = 1)
; Default Value: 1
; Development Value: 1
; Production Value: -1
; http://PHP.net/zend.assertions
zend.assertions = 1

该脚本现在按预期工作.

:~/code/x/test$PHP x.PHP
Hello
PHP Warning:  assert(): assert(false) Failed in /home/ubuntu/code/x/test/x.PHP on line 8

脚本宝典总结

以上是脚本宝典为你收集整理的断言不能在php中工作.很简单.我究竟做错了什么?全部内容,希望文章能够帮你解决断言不能在php中工作.很简单.我究竟做错了什么?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。