Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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('error::function'))?
  • Is it recommended?
like image 957
Shoe Avatar asked Jan 23 '11 11:01

Shoe


2 Answers

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');
like image 163
Gumbo Avatar answered Oct 21 '22 00:10

Gumbo


Yes; this syntax works:

set_error_handler('error::function');

As stated in the doc, you just have to pass a valid callback. http://php.net/manual/en/language.pseudo-types.php#language.types.callback(dead link)

like image 2
Arnaud Le Blanc Avatar answered Oct 21 '22 02:10

Arnaud Le Blanc