Set_error_handler with static-method callback
I RTM
but I couldn't find any nice answer to this question, so here is it:
- Can I call a static
method as an error handler (for example:
set_error_handler(开发者_StackOverflow中文版'error::function')
)? - Is it recommended?
set_error_handler
expects a value of the pseudo-type callback. And in the examples there you can see that there are two ways to specify a static method:
set_error_handler(array('Class', 'method'));
// since PHP 5.2.3
set_error_handler('Class::method');
Yes; this syntax works:
set_error_handler('error::function');
As stated in the doc, you just have to pass a valid callback. (dead link)http://php.net/manual/en/language.pseudo-types.php#language.types.callback
精彩评论