given the following script
<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
thisisanerror
?>
I get the expected
Notice: Use of undefined constant error - assumed 'error' in /htdocs/test.php on line 8
but if I add something to the script
<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
error
function test () {
echo('test');
}
?>
I get
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
Why am I getting a 500 error instead of a normal syntax error in the latter case? Shouldn't display_errors always display the error?
The second code sample is an outright syntax error. This means PHP will not progress to the point of code execution and will die at parse time. Since no code is executed, the effects of the ini_set() call are not seen, so you do not get the PHP textual error indicating the problem.
A parse error is fatal, and the web server is (rightly) set to handle PHP fatal errors with a 500 response code. Since your PHP script did not produce any output the web server will return it's default error document for the 500 condition.
If you want to see the textual message for parse errors in the browser - and one wouldn't normally do this is production, by the way - you will need to turn error reporting on in php.ini or using a .htaccess file.
If forcing php to show error on run time doesn't work for you, you may try other options like setting it in php.ini instead:
error_reporting = E_ALL | E_STRICT
display_errors: On
Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With