Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

html - How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

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);

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

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:

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

Any ideas?

EDIT:

I've reconfigured my code:

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...