Occasionally I will have some badly formed PHP code and I will get a 500 error. I'm running Apache 2.2 on a Windows 7 laptop. As an IDE I have started using PhpStorm.
What is the best way to catch these errors and be informed of the line number? Why do the OOP-related syntax errors tend to throw 500 errors and function problems tend to return normal errors?
Example of syntax mistake: calling a static method from a class with a single colon instead of two colons.
UPDATE: Please see accepted answer and all comments.
PHP will respond with a "500" when it encounters a Fatal error, such as E_PARSE
, E_ERROR
and uncaught exceptions. 500 is the HTTP response code for "Internal Server Error" - something unrecoverable happened while processing the request.
In your php.ini, on a development machine, you should set your error_reporting
level to (at least) E_NOTICE
- preferably E_ALL
- and make sure display_errors
is on. This will show you the error message in the browser, including for "500" errors.
You can also check your Apache error logs, the errors will be listed there, as long as log_errors
is enabled in php.ini. By default, this will be at <apache_ServerRoot>\logs\error.log
.
You can also control all this at run time with ini_set()
and error_reporting()
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