Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: set_error_handler and visibily

In my class constructor, I have the following:

set_error_handler(array(
    $this,
    '_custom_error_handler'
));

In the same class, I have the following method defined:

protected function _custom_error_handler($error_number, $error_string, $error_file, $error_line)

When something in my code runs into an error, I get the following warning:

Warning: Invalid callback ... _custom_error_handler, cannot access protected method

Why can't this class (or its children?) access this protected method? Shouldn't a protected method be accessible???

like image 481
StackOverflowNewbie Avatar asked Jul 29 '26 21:07

StackOverflowNewbie


1 Answers

A protected method is only accessible from inside the class, or subclasses.

In this case set_error_handler is calling a method, and set_error_handler is outside your class. Therefore it must be public.

like image 61
Evert Avatar answered Aug 01 '26 12:08

Evert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!