Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there patterns for handling errors in PHP projects?

Tags:

php

I wonder what patterns are there for handling errors in PHP?

I'm close to just make an global ErrorManager object which has methods to add messages. As my entire app gets compiled, any occuring error is logged to that ErrorManager object. At the end of my Front Controller (the last few lines of the script) I tell the ErrorManager to display errors (if any). One fancy thing I thought about: Visitors really don't care about technical details. Instead they should receive an beautiful error page with a big "SORRY" and an info that the error was reported. Then, the ErrorManager sends an E-Mail to the admin with all available information and logs that stuff to a error log file. This file can be seen through the backend, to make development easy.

No idea if this is a good strategy. I bet you know better ones :-)

like image 499
openfrog Avatar asked Dec 27 '09 16:12

openfrog


People also ask

How is error handling done in PHP?

By default, PHP sends an error log to the server's logging system or a file, depending on how the error_log configuration is set in the php. ini file. By using the error_log() function you can send error logs to a specified file or a remote destination.

What are the three types of errors How are errors different from exceptions in PHP?

There are three (3) types of fatal errors: Startup fatal error (when the system can't run the code at installation) Compile time fatal error (when a programmer tries to use nonexistent data) Runtime fatal error (happens while the program is running, causing the code to stop working completely)

What are PHP error handling keywords?

PHP error handling keywordsThrow: The throw keyword is used to signal the occurrence of a PHP exception. The PHP runtime will then try to find a catch statement to handle the exception. Catch: This block of code will be called only if an exception occurs within the try code block.

How is exception and error handling done in PHP?

The default error handling in PHP is very simple. An error message with filename, line number and a message describing the error is sent to the browser. Exceptions are used to change the normal flow of a script if a specified error occurs. This can be done using PHP die() Function.


1 Answers

PHP Manual

  • http://de3.php.net/errorfunc
  • http://www.php.net/manual/en/language.exceptions.php

In General

  • http://devzone.zend.com/article/1303-Error-Handling-Stepping-beyond-TrueFalse-Results
  • http://devzone.zend.com/article/666-Exceptional-Code---PART-1

In MVC (ex. ZF)

  • http://framework.zend.com/manual/en/zend.controller.exceptions.html
  • http://www.dragonbe.com/2007/11/error-handling-in-zend-framework.html
  • http://www.talkincode.com/a-useful-error-controller-class-for-zend-framework-applications-729.html
like image 185
Gordon Avatar answered Sep 18 '22 01:09

Gordon