PHP中ini_set()的用途是什么? (尤其是对于错误报告) [英] What's the purpose of ini_set() in php? (especially for error reporting)

查看:99
本文介绍了PHP中ini_set()的用途是什么? (尤其是对于错误报告)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,因此PHP具有 ini_set()函数,很多人都知道,它们将用于设置各种配置选项(此处)以帮助进行开发等。但是,此功能似乎仅在运行时有效,如果在运行时不起作用是任何致命错误,或者脚本有语法错误,无法对其进行解析/编译。

Ok so PHP has the function ini_set() which a lot of people are aware of and will use to set various configuration options (here) to help with development etc. However, this function does only seem to work at runtime and will not work if there are any fatal errors or the script has syntax errors and can't be parsed / compiled.

因此,毫无疑问(从手册中)可以做到这一点:

Therefore surely there is no point of doing this (from the manual):


http://php.net/manual/zh/function.ini-set.php

示例

示例#1设置ini选项

Example #1 Setting an ini option



<?php
echo ini_get('display_errors');

if (!ini_get('display_errors')) {
    ini_set('display_errors', '1');
}

echo ini_get('display_errors');
?>

我不知道我是否只是缺少某些东西,而我的php.ini没有配置正确,但是很多时候我都没有错误。对于初学者/大三学生来说,无疑会有很多语法错误(缺少分号,右括号等),并且说初中生会寻找打开错误的方法,并假设上面的手动输入正确无误,但在重新运行时他们的脚本,可惜他们没有错误,因为脚本无法首先解析/编译。

I don't know if I'm just missing something and my php.ini isn't configured correctly, but a lot of the time I get no errors. For beginners / juniors there will no doubt be a lot of syntax errors (missing semi-colons, closing brackets etc), and said juniors would search for how to turn on errors, assume the above manual entry is correct, yet when re-running their script, alas, they get no errors as the script cannot be parsed / compiled in the first place.

我知道您可以设置 display_errors =在php.ini文件中上,然后重新启动Web服务器以将所有错误显示在屏幕上(在开发环境中使用此命令,肯定不存在),但是最好不要删除该错误。功能,并且仅针对不同的错误级别配置 php.ini 文件?

I know you can set display_errors = On in the php.ini file and restart your web server to show all errors to the screen (using this in a development environment, definitely not live), but wouldn't it be better just to remove the function and only configure the php.ini file for different error levels?

更新:

我知道ini_set不仅用于显示错误,但是如果您在某些脚本/函数/文件中调用ini_set,那么代码就不是非常易于管理的,这是否更有意义可以使用php.ini这样的东西?

I know ini_set isn't just for displaying errors, but code can't be very manageable if you're calling ini_set in certain scripts / functions / files and wouldn't it make more sense to use the php.ini for something like that?

更新

因此ini文件可用于设置全局配置选项,当然您可以将其用于安全性或优化性,但是开发人员仍然可以使用ini_set覆盖某些内容这些选项可能在运行时并不理想

So the ini file can be used to set global configuration options, surely you'd use this for security or optimisation, however developers could still use ini_set to override some of these options at runtime which may not be desirable

总结(@Hanky웃Panky):

In summary (@Hanky웃Panky):

当一些琐碎的语法错误仍不会显示时,为什么我可以选择显示错误?

Why do I have the option of displaying errors when some trivial syntax errors will still not display?

推荐答案

是的,您是对的,只是删除功能并仅针对不同的错误级别配置php.ini文件。

yes, you are right that its better just to remove the function and only configure the php.ini file for different error levels.

但是,仅当您的机器中只有一个项目,因此,它的所有配置设置都可以在php.ini
中进行考虑,如果您有多个项目设置,则为这种情况。如果您不希望该项目中的某些设置仍然可以从php.ini中获得

But, this is good only that case when you have only one project in your machine, So, its all configuration setting you can do in php.ini Consider, the case if you have multiple project setup. if you don't want some settings in that project still it will get from php.ini

因此,建议您将某些配置设置设置为项目级别与ini_set()一起使用,并且不会反映其他项目。

So, it is suggested for some configuration settings you just set them at project level with ini_set() and will not reflect other projects.

这篇关于PHP中ini_set()的用途是什么? (尤其是对于错误报告)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆