Is there any way to pass variable to the set_exception_handler() method in PHP? I need something like this:
class Clazz {
public /* static */ function foo() {
set_exception_handler(array('Clazz', 'callback'), $var); // I need to pass $var
// or this in non-static context
$that = $this;
set_exception_handler(array($that, 'callback'), $var); // I need to pass $var
}
public static function callback($exception, $var) {
// process $exception using $var
}
}
As i already indicated in the comment you have to use lambda-functions anyway:
$lambda = function($exception) use ($var) {
Clazz::callback($exception,$var);
}
set_exception_handler($lambda);
Use a callback
set_exception_handler(function($exception) use($var){
$that->callback($exception, $var);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With