就像断言甚至没有被调用一样。我很困惑。
版本
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
剧本:
x.php
<?php
print ("Hello\n");
assert_options(ASSERT_ACTIVE,true);
assert_options(ASSERT_BAIL,true);
assert(false);
assert(true);
print ("Bye\n");
当我运行它时
php x.php
Hello
Bye
我原以为程序会因异常而终止。我要疯了吗?
看起来断言在 7.0 上是开箱即用的。在我的php.ini file zend.断言设置为-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
该脚本现在可以按预期工作。
php x.php
Hello
PHP Warning: assert(): assert(false) failed in /home/ubuntu/code/x/test/x.php on line 8
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)