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
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Error Handler

Post by Sphenn »

Hi,

Does anyone know if you can use a class as an error handler?

I've looked through the documentation, and can't find any info, and my own tests have been inconclusive.

Thanks
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

In which way, what is the structure of the class and/or your systems logic, and how are you invoking the errors?

Code: Select all

<?php
class error 
{
    function handler($errno, $errstr, $errfile, $errline)
    {
        echo "$errno, $errstr, $errfile, $errline";
    }
}

set_error_handler(array('error', 'handler'));

trigger_error('this is an error', E_USER_WARNING);

?>
As a static call, using trigger_error and set_error_handler. You can also use the object variable instead of a the (string) ClassName to use an object.
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Ahh...thanks so much

I have an error handler defined, than decides wether or not to send e-mails, log, etc. I'll be calling it using trigger_error().

Thanks again
Post Reply