note 58086 modified in function.set-exception-handler by derick
| From: | derick@php.net | Date: | Tue, 25 Oct 2005 10:22:39 +0000 |
| Subject: | note 58086 modified in function.set-exception-handler by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97558@lists.php.net to get a copy of this message | ||
Using the 'set_exception_handler' function within a class, the defined
'exception_handler' method must be declared as 'public' (preferrable
'public static' if you use the "array('example',
'exception_handler')" syntax).
<?php
class example {
public function __construct() {
@set_exception_handler(array('example', 'exception_handler'));
throw new Exception('DOH!!');
}
public static function exception_handler($exception) {
print "Exception Caught: ". $exception->getMessage() ."\n";
}
}
$example = new example;
echo "Not Executed\n";
?>
Declaring the 'exception_handler' function as 'private' causes a FATAL ERROR.
[derick: red. updated statement about static a bit]
--was--
Using the 'set_exception_handler' function within a class, the defined
'exception_handler' method must be declared as 'public' or 'static'
(or 'public static').
<?php
class example {
public function __construct() {
@set_exception_handler(array('example', 'exception_handler'));
throw new Exception('DOH!!');
}
public static function exception_handler($exception) {
print "Exception Caught: ". $exception->getMessage() ."\n";
}
}
$example = new example;
echo "Not Executed\n";
?>
Declaring the 'exception_handler' function as 'private' causes a FATAL ERROR.
http://php.net/manual/en/function.set-exception-handler.php