sunilvadranapu Posted April 22, 2008 Share Posted April 22, 2008 Hi, I am writing a PHP class for custom error handling. In constructor i am setting up the error handler like this. function __construct (){ { if (error_reporting() == 0) return; $this->logger = new Logger("mylog.log","append") ; //create object to logger class set_error_handler(array($this,"ErrorHandler")); //set user defined error handler } while running the i am getting below warning: Warning: set_error_handler() expects the argument (Error::ErrorHandler) to be a valid callback in C:\php_dev\errorHandler \sun_error.php on line 16 what is this waring? can any one tell me how can i remove this warning?? thanks in advance -sun Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 The set_error_handler function just needs the name of another function that will be used to handle errors, not an array. set_error_handler(); Quote Link to comment Share on other sites More sharing options...
sunilvadranapu Posted April 22, 2008 Author Share Posted April 22, 2008 As far as i know, i am using set_error_handler inside the class , i am passing the array. If we use the set_error_handler out side the class, then its enough to mention the "error handler" Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 PHP doesn't WANT an array for that function: mixed set_error_handler ( callback $error_handler [, int $error_types ] ) You need to just pass a function name. Make a function that calls a Logger object, and then use that function for the set_error_handler. You need to be a bit creative for it to work though. Quote Link to comment Share on other sites More sharing options...
sunilvadranapu Posted April 22, 2008 Author Share Posted April 22, 2008 thanks for your reply. In my "Error" class i have constructor and ErrorHandler() method. Class: Error constructor ErrorHandler i changed the constructor code to set user defined error handler to Error Class method "ErrorHandler" set_error_handler("ErrorHandler"); even then i am getting the warning msg: Warning: set_error_handler() expects the argument (ErrorHandler) to be a valid callback in C:\php_dev\errorHandler\sun_error.php on line 16 thanks in advance Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 thanks for your reply. In my "Error" class i have constructor and ErrorHandler() method. Class: Error constructor ErrorHandler i changed the constructor code to set user defined error handler to Error Class method "ErrorHandler" set_error_handler("ErrorHandler"); even then i am getting the warning msg: Warning: set_error_handler() expects the argument (ErrorHandler) to be a valid callback in C:\php_dev\errorHandler\sun_error.php on line 16 thanks in advance Make a function SEPARATE of the class that creates a new Error object (sorry, I thought you named it Logger when I posted my previous post), and use THAT function as the error handler, and work with the object in it. Quote Link to comment Share on other sites More sharing options...
sunilvadranapu Posted April 22, 2008 Author Share Posted April 22, 2008 This is my actual class: <?php class Error { function __construct (){ { if (error_reporting() == 0) return; //set_error_handler(array($this,"ErrorHandler")); set_error_handler("ErrorHandler"); } function ErrorHandler($errno,$errstr,$errfile,$errline) { $errorType = array ( E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE', E_STRICT => 'STRICT NOTICE', E_RECOVERABLE_ERROR => 'RECOVERABLE ERROR' ); $errtime=date("Y-m-d H:i:s (T)"); $err_message="An error occured on ".$errtime."\n"; $err_message .="Details are as follows\n"; $err_message .="Error Number : $errno\n"; $err_message .=$errstr."\nOccured in ".$errfile."\n"; $err_message .="On Line $errline \n\n"; $err_message .=str_repeat("-",50); $err_message .="\n"; } } //class ?> Quote Link to comment Share on other sites More sharing options...
sunilvadranapu Posted April 23, 2008 Author Share Posted April 23, 2008 My intension is to write a PHP class for handling errors. thats why i am developing the "Error" class which has a constructor in which i am setting up the user defined error handler and a "ErrorHandler" method which handles all errors encountered while execution. please help me in this regard thanks in advance Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.