Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

PHP error handling

Hi,

I am just starting out with phalcon i set it up with docker but i'm having some problems if I make a typo or some syntax error, this is not shown in my browser instead i get this:

This page isn’t working

localhost is currently unable to handle this request. HTTP ERROR 500

Do I need to enable something. I'm using this example code: https://github.com/phalcon/mvc/tree/master/simple/apps



7.1k

Are your typos in URLs or code?

For code, you need PHP errors switched on. There are settings to send the errors to a log or to the screen. For an extreme error, where PHP cannot compile the code, the error is classed as a startup error. There is a PHP setting to display startup errors.

Look through your PHP error settings and the log settings. Look in your logs.



973

this was intetionaly typo, just to see if errors are shown, like missing ";" But I would also like to see if I instatiate some phalcon class and it's maybe missing to be shown.

You said settings, what kind of settings? phalcon settings?



59.2k
Accepted
answer
edited Aug '17
// output errors to browser
ini_set('display_errors', 1);
// report all errors
error_reporting(E_ALL);
// convert warnings/notices to exceptions
set_error_handler(function($errno, $errstr, $errfile, $errline) {
    throw new \Exception($errstr.PHP_EOL.$errfile.":".$errline, $errno);
});

These are all vanilla PHP commands



7.1k

Note that a PHP setting made in PHP code will not handle PHP errors before the setting. Put the settings in the PHP or Web server config.

Finding and accessing all the log files is still good practice. You find all sorts of weird errors and warnings. Processing those conditions usually slows down your Web site. Worth investigating and fixing. You also get pre PHP errors when moving to a new server or OS or host. Again you need to see the logs that contain PHP compiler startup errors.