We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



9.7k

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.



2.2k

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?



77.7k
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



9.7k

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.