2

In an action method, I have the following excerpt of code:

error_reporting(E_ALL);
ini_set('display_errors', '1');
Logger::log('test');

The Logger class is defined in this way:

class Logger {
    public static function log() {
        echo "test";
}

I deliberately forgot the closing brace of the function to demonstrate the problem. When the action is called, absolutely nothing is rendered on the screen. What type of error is this, and why is it not displayed, even though I configured PHP to show all errors, as shown above?

Of course, if I add the missing brace, everything is OK.

Ariod
  • 5,757
  • 22
  • 73
  • 103
  • have you checked your configs/application.ini ? – Hannes Oct 15 '10 at 11:44
  • Thanks, but what should I check? I explicitly reconfigured PHP error settings just before calling Logger:log() to make sure that all PHP errors are shown. – Ariod Oct 15 '10 at 11:52
  • I don't have any log writers. Don't let the class name "Logger" confuse you, I am just wondering why no errors are shown when a static function of an invalid class is called. – Ariod Oct 15 '10 at 12:07
  • Gordon, I don't see how PHP parser could even get to the line where die() is, because the Logger class itself is invalid. PHP breaks at the moment of parsing the Logger class, but it doesn't show an error message or any indication that this class is invalid. – Ariod Oct 15 '10 at 12:25

2 Answers2

3

You also have to enable display_startup_errors to show Fatal errors:

Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. It's strongly recommended to keep display_startup_errors off, except for debugging.

Also see the Note for display_errors:

Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.

You can set both values in Zend Framework's application.ini. On a sidenote: if you set error_reporting(-1) it will report (!display) all errors, including E_STRICT and any future additions.

Gordon
  • 312,688
  • 75
  • 539
  • 559
  • Thanks for the effort Gordon, it appears that `display_startup_errors` had already been set in the config file. In fact, if I run `ini_get('display_startup_errors')` and `ini_get('display_errors')`, both functions return 1. Still no luck. – Ariod Oct 15 '10 at 13:02
  • @Dario are you sure there is not any error suppression operators `@` anywhere before the Logger class is loaded? Can you check your webserver's error log? – Gordon Oct 15 '10 at 13:21
  • Nope, no suppression operators. Interestingly, if I miss out a brace in the controller class, I will get PHP error on screen as well as in the server log: `PHP Parse error: syntax error, unexpected T_IF`. However, nothing is displayed if I use an invalid class within the controller, like in my example. As if such errors are completely lost during view rendering. – Ariod Oct 15 '10 at 13:37
  • @Dario cant help then. Install XDebug and step through the code. This will show you what happens. – Gordon Oct 15 '10 at 13:45
2

I have exactly the same problem - I didn't manage to completely solve it, but I found out that all errors are correctly logged to a file, even though they are not displayed.

Just put this lines in your .htaccess/server config:

php_value       log_errors                      On
php_value       error_log                       "/path_to_logs/errors.log"
Pimgd
  • 5,983
  • 1
  • 30
  • 45
zeroos
  • 2,094
  • 3
  • 17
  • 24