error_reporting() 和 ini_set('error_reporting') 之间的区别?

发布于 2024-08-15 16:22:50 字数 216 浏览 3 评论 0原文

在我的脚本中使用 error_reporting()ini_set('error_reporting') 时,两者之间是否存在功能差异?一种方法优于另一种方法吗?

就其价值而言,我看到许多框架使用 error_reporting(),但这两个选项似乎仅在运行时设置,然后在脚本执行后重置回 php.ini 中的默认值。

When using error_reporting() or ini_set('error_reporting') in my scripts, are there any functionality differences between the two? Is one method preferred over the other?

For what it's worth, I see many frameworks using error_reporting(), but both options appear to be set during runtime only, then reset back to their default in php.ini after script execution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只有影子陪我不离不弃 2024-08-22 16:22:50

唯一小的功能差异似乎是 ini_set 在无法更改设置时返回 false,而 error_reporting 始终返回旧的错误级别。

The only small functional difference seems to be that ini_set returns false when it was unable to change the setting and error_reporting always returns the old error level.

待天淡蓝洁白时 2024-08-22 16:22:50

“两条路通罗马”: ini_set('error_reporting', ) 覆盖 php.ini 文件中设置的参数。 error_reporting() 接收级别编号或级别 id

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

这两个选项都将生效,直到脚本结束执行。下一个将再次使用 .ini 中定义的参数。

"Two roads leading you to Rome": ini_set('error_reporting', ) overrides the parameter set in the php.ini file. error_reporting() receives level number or level id

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

Both options take effect until the script ends its execution. The next one will use the params defined in the .ini, again.

橪书 2024-08-22 16:22:50

它们在功能上是相同的,但如果您使用的 IDE 知道 PHP 函数名称,那么这是一种简单的方法,可以确保您不会意外地输错要设置的指令的名称。

PHP 的 error_reporting() 手动输入<的示例部分/代码>

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

They are functionally identical, but if you are using an IDE that knows the PHP function names, this is an easy way to make sure you don't accidentally mistype the name of the directive you are tying to set.

From the examples section on PHP's Manual Entry for error_reporting():

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
花之痕靓丽 2024-08-22 16:22:50

另外,尽管文档指出 error_reporting 的签名 是:

int error_reporting ([ int $level ] )

,它并不完全正确,因为您可以设置一个 string 并使用 ini_get 读回它:

error_reporting('123 hello world');

var_dump(ini_get('error_reporting'));

产生:

string(15) "123 你好世界"

因此,error_reporting($x) 在语义上等价于 ini_set('error_reporting', $x)

error_reporting() 在语义上等价于(int)ini_get('error_reporting')

Also, even though the docs stated that the signature for error_reporting is:

int error_reporting ([ int $level ] )

, it's not exactly correct because you can set a string and read it back with ini_get:

error_reporting('123 hello world');

var_dump(ini_get('error_reporting'));

produces:

string(15) "123 hello world"

So, error_reporting($x) is semantically equivalent to ini_set('error_reporting', $x),

and error_reporting() is semantically equivalent to (int)ini_get('error_reporting').

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文