Jump to content

Recommended Posts

I have a class Page which handles any given pages needed resources and output/display. IE, it does the database connections, session handling, and general html output.

 

I want to use override the default error handler for PHP using set_error_handler() inside of this Page class, however I am having problems accessing the method errorHandler.

 

<?

function errorHandler($errno, $errstr, $errfile, $errline)
{
	switch ($errno) {
		case E_USER_ERROR:
			echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
			echo "  Fatal error on line $errline in file $errfile";
			echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
			echo "Aborting...<br />\n";
			exit(1);
			break;

		case E_USER_WARNING:
			echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
			break;

		case E_USER_NOTICE:
			echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
			break;

		default:
			echo "Unknown error type: [$errno] $errstr<br />\n";
			break;
		}

	return true;
}
?>

 

However, I am having a very hard time accessing this method through set_error_handler, from within the class.

 

I have tried:

 

<?
set_error_handler('Page::errorHandler');
set_error_handler(Page::errorHandler);
set_error_handler('Page::errorHandler()');
set_error_handler(Page::errorHandler($errno, $errstr, $errfile, $errline));
set_error_handler('Page::errorHandler($errno, $errstr, $errfile, $errline)');
set_error_handler(Page::errorHandler());
set_error_handler('$this->errorHandler');
set_error_handler('Page::errorHandler()');
set_error_handler('$this->errorHandler');
set_error_handler('$this->errorHandler()');
set_error_handler('$this->errorHandler($errno, $errstr, $errfile, $errline)');
set_error_handler($this->errorHandler());
set_error_handler($this->errorHandler($errno, $errstr, $errfile, $errline));
?>

 

All with relatively no success. If this catches certain errors, i want to throw my custom throwError or throwWarning functions, however, the first step is finding out how to properly access my callback function through set_error_handler();

 

If you have any ideas, insight etc that may be useful, please let me know.

 

The straight down and dirty question is: How do I access a callback method belonging to a class, from that class's constructor.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/66504-error-handling-in-object/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.