Jump to content

[SOLVED] Set_error_handler die but return true


inactive

Recommended Posts

Hey homies,

 

Is there anyway in the function I set in set_error_handler() to return true, and die?

 

My code:

<?php
set_error_handler('my_error_handler');

function my_error_handler($errno, $errstr, $errfile, $errline) {
// ... handle error here ... //
}

echo  1/0; // generates a warning
trigger_error('Some Other Error', E_USER_ERROR); // generates user error

?>

 

What the my_error_handler() function does will depend on the error type:

 

1) In the case of the warning, after handling the error, it will return true, so that the normal PHP error handler will log the error in the normal error log, and then it will let the rest of the script proceed. This works great.

 

2) In the case of the user error, I need it to handle the error, then return true, so that the normal PHP error handler will log the error in the normal error log, and then exit. I cannot get this to work.  ???

 

Is there a way to return true, and exit/die?

 

If I don't exit/die, the rest of the script will continue to run, with detrimental results. If I do exit, then it is not possible to return true, which means the error won't be logged properly by the normal PHP error handler.

 

I.e:

<?php
exit(); // script will exit,
return true; // but will not return true (obviously, as the script has already terminated)
?>

<?php
return true; // script will return true,
exit(); // but as it has now jumped out of this function, will now not exit
?>

 

Any ideas? Is this even possible?

 

Thanks in advance.

The PHP internal error handler will not be executed unless the error handling function returns true. I need this to happen.

Returning true, false, not returning anything has no effect on the actual script itself.

 

See the example here:

http://au.php.net/manual/en/function.set-error-handler.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.