Page 1 of 1
Setting a custom Error Handler
Posted: Sun Jul 23, 2006 11:49 am
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.
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?

Posted: Sun Jul 23, 2006 11:52 am
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.
Posted: Sun Jul 23, 2006 11:56 am
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.
Posted: Sun Jul 23, 2006 11:58 am
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?
Posted: Sun Jul 23, 2006 11:58 am
by feyd
You can use
trigger_error() to send errors.
Posted: Sun Jul 23, 2006 12:06 pm
by daedalus__
Use that everywhere to send the errors to my handler rather than php?
Posted: Sun Jul 23, 2006 12:11 pm
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.
Posted: Sun Jul 23, 2006 12:14 pm
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);
?
Posted: Sun Jul 23, 2006 12:28 pm
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.
Posted: Sun Jul 23, 2006 12:32 pm
by daedalus__
Thinking about my question more, the code probably shouldn't have any fatal or parse errors anyway..