php WAMP:如何在浏览器中显示警告消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/771241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WAMP: How to show warning messages in browser?
提问by Shyju
I have a WAMP installation on my machine and I am developing a PHP website in that. Can anyone tell me what settings to be changed in order to show all errors / warning messages in the browser?
我在我的机器上安装了 WAMP,我正在开发一个 PHP 网站。谁能告诉我要更改哪些设置才能在浏览器中显示所有错误/警告消息?
Thanks in advance
提前致谢
回答by thomasrutter
You need to set both error_reportingand display_errors. These can be set in php.ini, in Apache (if you're using PHP as an Apache module) or during run-time, though if you set it during run-time then it won't effect some types of errors, such as parse errors.
您需要同时设置error_reporting和display_errors。这些可以在 php.ini、Apache(如果您使用 PHP 作为 Apache 模块)或运行时设置,但如果您在运行时设置它,则不会影响某些类型的错误,例如作为解析错误。
For portability - that is, if you want to set this in the application - try setting them in an .htaccess:
为了可移植性 - 也就是说,如果你想在应用程序中设置它 - 尝试在 .htaccess 中设置它们:
# note: PHP constants such as E_ALL can't be used when setting it in Apache
php_value error_reporting 2147483647
php_flag display_errors on
Alternatively you could set these in httpd.conf
或者,您可以在 httpd.conf 中设置这些
display_errorsmakes sure that all reported errors are actually output to the browser (on a live server, it's typical to log them to a file instead). error_reportingspecifies which types errors should be logged/displayed.
display_errors确保所有报告的错误实际上都输出到浏览器(在实时服务器上,通常将它们记录到文件中)。 error_reporting指定应记录/显示哪些类型的错误。
For a live server, it's generally a good idea to not to display errors publicly (but you may still want to log them). Either way, it's still a good idea to set error_reporting to a more inclusive value (2147483647 being the most inclusive value possible now and for the future according to the PHP docs) because ignoring errors is generally a bad idea.
对于实时服务器,通常最好不要公开显示错误(但您可能仍想记录它们)。无论哪种方式,将 error_reporting 设置为更具包容性的值仍然是一个好主意(根据 PHP 文档,2147483647 是现在和未来可能的最具包容性的值),因为忽略错误通常是一个坏主意。
回答by Shyju
First click on the wamp icon in the task panel. Then click on the 'PHP' folder followed by the 'PHP settings' folder. Make sure 'expose PHP' and 'display errors' are both checked. You can set other error settings like 'track errors' and 'display startup errors' as well.
首先单击任务面板中的 wamp 图标。然后单击“PHP”文件夹,然后单击“PHP 设置”文件夹。确保 'expose PHP' 和 'display errors' 都被选中。您还可以设置其他错误设置,例如“跟踪错误”和“显示启动错误”。
回答by Fuzzy76
Find your php.ini file, scroll down while reading the comments. There is a global setting for enabling/disabling error output. Change it accordingly. Restart your Apache.
找到您的 php.ini 文件,在阅读评论时向下滚动。有一个用于启用/禁用错误输出的全局设置。相应地更改它。重新启动您的 Apache。
回答by NormundsP
I always use this code:
我总是使用这个代码:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
If you write code using OOP PHP, then create new methond showError()and call it in every file you need.
如果您使用 OOP PHP 编写代码,则创建新方法showError()并在您需要的每个文件中调用它。
回答by Kifayat Ullah
If someone is using CodeIgniter then pass this code in constructor of controller. This will solve your problem.
如果有人正在使用 CodeIgniter,则将此代码传递到控制器的构造函数中。这将解决您的问题。
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
回答by Daniel Rikowski
Open your php.iniand search for the option error_reporting.
打开您的php.ini并搜索选项error_reporting。
Change it to E_ALL & ~E_NOTICE.
将其更改为E_ALL & ~E_NOTICE.
That will show all errors and warnings, but no notices.
这将显示所有错误和警告,但不会显示任何通知。
Personally I always use E_ALLon my development machines because often the notices are signs to potential code problems.
我个人总是E_ALL在我的开发机器上使用,因为这些通知通常是潜在代码问题的迹象。

