在我的类构造函数中,我有以下内容:
set_error_handler(array(
$this,
'_custom_error_handler'
));
在同一个类中,我定义了以下方法:
protected function _custom_error_handler($error_number, $error_string, $error_file, $error_line)
当我的代码中出现错误时,我会收到以下警告:
Warning: Invalid callback ... _custom_error_handler, cannot access protected method
为什么这个类(或其子类?)不能访问这个 protected 方法? protected 方法不应该是可访问的吗???
最佳答案
protected 方法只能从类或子类内部访问。
在这种情况下,set_error_handler 正在调用一个方法,而 set_error_handler 在您的类之外。因此它必须是公开的。
关于PHP: set_error_handler 和 visibily,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44656352/