Setting a custom Error Handler

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Setting a custom Error Handler

Post by daedalus__ »

I just worked from 8 pm to 5:30 am on this custom error handling class and for some reasom PHP won't use the thing. :x

Code: Select all

set_error_handler(array($this, 'LogError'));
I use that in the constructor of the class, it does not produce any errors though PHP does not use that function.

wth? :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What errors are you sending to it? If they are fatals, they will generally not be sent as they are often derived from parsing errors which often happen before any code has been run.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

This one should be, an echo get through before the Fatal Error does which means that the class was instantiated.

Though, I didn't know there was a way to specify which errors to send to it, but I want to send four kinds:

E_ERROR
E_WARNING
E_NOTICE
E_CUSTOM (made it meself)

I'd like to send parse errors to it especially but as far as I know, you can't?

P.S. I'm tired and may become stupid during the course of this thread, and the one I am (hopefully) about to post.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I guess you were right, it won't take the fatal error, i thought the easiet way to make one would be to call an undefined function, but that is kind of a parse error right?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can use trigger_error() to send errors.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Use that everywhere to send the errors to my handler rather than php?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Daedalus- wrote:Use that everywhere to send the errors to my handler rather than php?
Wha? If you wanted a trigger an error, be it a notice or a fatal error you can use trigger_error() to report an error to your error handler.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

yeah but i meant, what i want to send things like fatal and parse errors on to my error handler, can i use trigger_error()?

Code: Select all

// undefined function
UndefinedFunction($param) or trigger_error($params);
?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Parse and most other fatal errors will be handled by php when it reads the file or code. As I said before, this is done, more often than not, before any of your code has been run. So on the whole, no, using trigger_error() like that will not work.. however you could use function_exists(), method_exists(), and class_exists() for detecting, then use trigger_error() with the results from that call.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Thinking about my question more, the code probably shouldn't have any fatal or parse errors anyway..
Post Reply