error reporting problem[solved]

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
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

error reporting problem[solved]

Post by raghavan20 »

I have an error handler, i do not receive fatal error calls to this function. Here, I intentionally mispell an object and try to call a method that belongs to the object. i get the notice error in handler but not the fatal error. Any ideas?

received error on screen

Code: Select all

my error handler called
; errno: 8; errstr: Undefined variable: TemplateManager
current run type: production
Fatal error: Call to a member function getUnit() on a non-object in /home/thisisra/public_html/home/controllers/PW_C_AboutMe.php on line 45
the error handler

Code: Select all

//define error handler
function myErrorHandler($errno, $errstr, $errfile, $errline){
	
	echo "<h4>my error handler called</h4>; errno: $errno; errstr: $errstr";
	echo "<br />current run type: " . CurrentRunType;
	$msg = "
	<div style = 'text-align:center;'>
		<h3>www.thisisraghavan.com</h3>
		I am aware of this error and I will fix this soon. 
		I appreciate your co-operation
	</div>";
	
	switch ( TRUE ) {
	 	case ( $errno == E_USER_ERROR || $errno == 1 ):{
			if( CurrentRunType == 'test' ){
				
				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";
				
			}else{
				echo $msg;
			}
			exit(1);
			break;
		}
		
		case ( $errno == E_USER_WARNING || $errno == 2 ):{
			if( CurrentRunType == 'test' ){
				echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
			}
			break;
		}
		
		case ( $errno == E_USER_NOTICE || $errno == 8 ):{
			if( CurrentRunType == 'test' ){
				echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
			}
			break;
		}
		
		default:{
			if( CurrentRunType == 'test' ){
				echo "Unknown error type: [$errno] $errstr<br />\n";
			}
			break;
		}
	}

   /* Don't execute PHP internal error handler */
   return true;
}
Last edited by raghavan20 on Mon Feb 26, 2007 7:39 am, edited 1 time in total.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

This is either because your error handler was not loaded before the error occured, or more likely that this error causes an immediate exit with no further code execution, so its not possible to catch.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

raghavan20 wrote:Fatal error: Call to a member function getUnit() on a non-object in
http://de2.php.net/set_error_handler wrote:The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.
"Fatal error" means E_ERROR.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

volka wrote:
raghavan20 wrote:Fatal error: Call to a member function getUnit() on a non-object in
http://de2.php.net/set_error_handler wrote:The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.
"Fatal error" means E_ERROR.
that explains a lot. but if you cannot handle E_ERROR, then this is not going to be of much use as we cannot perform any error related operations or mailing, so the only chance of debugging would be looking at the error log.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

If you are using PHP 5 you should look into using exceptions, it might help you out. As for fatal errors, these are typically things that happen in development, not usually things that crop up later while the app is under use (assuming that your app is well written). Fatal errors are things like compile errors and other blatant things such as missing semicolons or in your case trying to access a method on something that isn't an object.
Post Reply