如何让PHP显示错误? (我添加了ini_set和error_reporting,但是只给出了500个错误) [英] How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

查看:170
本文介绍了如何让PHP显示错误? (我添加了ini_set和error_reporting,但是只给出了500个错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在当前的网页上并没有任何错误,但是我想在弹出时看到一个错误,而不是HTTP 500错误页面。我有点想了想,加上这两行会修复一切。

So, I don't really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bit and thought adding these two lines would fix everything.

ini_set('display_errors', 'On');
error_reporting(E_ALL);

注意:我没有访问php.ini文件,因为我正在使用我的学校帐户的服务器。

NOTE: I don't have access to the php.ini file, as I'm using my school account's server.

所以我介绍了一个错误(在$ bug后没有分号),如我的页面顶部:

So I introduced a bug (no semicolon after $buggy) like so at the top of my page:

<?php 
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$buggy

$x = 4 + 2;
...

但是,我只是得到一个服务器错误:

However, I just get a Server error:

网站在检索 http://mywebpage.com/ 时遇到错误,可能会关闭维护或配置不正确。

"The website encountered an error while retrieving http://mywebpage.com/. It may be down for maintenance or configured incorrectly."

任何想法?

编辑:

我重新配置了我的代码:

I've reconfigured my code:

<?php 
include_once 'database/errorSettings.php';
?>
<?php 

$buggy // whoops
$x = 4 + 2;
...

errorSettings.php如下:

errorSettings.php is the following:

<?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL);
?>

但它仍然不起作用...错误的重新配置方式?

But it still doesn't work... wrong way to reconfigure?

推荐答案

你有一个解析错误。在执行任何代码之前抛出这些错误。在其中的任何代码可以执行之前,需要解析PHP文件。如果在设置错误级别的文件中有一个解析错误,那么在抛出错误的时候它们将不会生效。

What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there's a parse error in the file where you're setting your error levels, they won't have taken effect by the time the error is thrown.

要么打破你的将文件分成较小的部分,例如将错误级别设置在一个文件中,然后包含另一个包含实际代码(和错误)的文件,或将错误级别设置为PHP外使用php.ini或.htaccess指令。

Either break your files up into smaller parts, like setting the error levels in one file and then includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.

这篇关于如何让PHP显示错误? (我添加了ini_set和error_reporting,但是只给出了500个错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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