Assert is not working in PHP. So simple. What am I doing wrong?(断言在PHP中不起作用。太简单了。我做错了什么?)
本文介绍了断言在PHP中不起作用。太简单了。我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就像Assert甚至没有被调用一样。我糊涂了。
版本
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
");
assert_options(ASSERT_ACTIVE,true);
assert_options(ASSERT_BAIL,true);
assert(false);
assert(true);
print ("Bye
");
当我运行它时
php x.php
Hello
Bye
我本以为程序会因异常而终止。我疯了吗?
推荐答案
看起来断言在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
脚本现在可以正常工作了。
php x.php
Hello
PHP Warning: assert(): assert(false) failed in /home/ubuntu/code/x/test/x.php on line 8
这篇关于断言在PHP中不起作用。太简单了。我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:断言在PHP中不起作用。太简单了。我做错了什么
基础教程推荐
猜你喜欢
- 为 iPhone APNS 使用 PHP 时出错 2022-01-01
- 在 Magento 中设置全局变量,GUI 方式? 2021-01-01
- PHP中如何获取当前用户的请求参数? 2023-09-25
- File_get_contents 不起作用? 2021-01-01
- PHP 5 反射 API 性能 2021-01-01
- 使用 jQuery Ajax 删除 mySQL 表行 2021-01-01
- Laravel Dusk:FacebookWebDriverExceptionUnknownErrorException:未知错误:NET::ERR_CONNECTION_REJECTED 2022-01-01
- 雄辩的 laravel WhereIn All 2021-01-01
- 使用 php 7 运行 composer,但为 php 5 安装包 2022-01-01
- PHP - 从时差中排除所有非营业时间/天 2022-01-01
