如何使用对象方法作为回调函数 [英] How to use an object method as a callback function
本文介绍了如何使用对象方法作为回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在单例课程中有以下方法
I have the below method in a singleton class
private function encode($inp)
{
if (is_array($inp) {
return array_map('$this->encode', $inp);
} else if is_scalar($inp) {
return str_replace('%7E', rawurlencode($inp));
} else {
return '';
}
}
这可以正常使用
function encode($inp)
{
if (is_array($inp) {
return array_map('encode', $inp);
} else if is_scalar($inp) {
return str_replace('%7E', rawurlencode($inp));
} else {
return '';
}
}
在类中使用时,出现以下错误:
when using inside a class i'm getting the below error:
PHP警告:array_map():第一个 参数"$ this-> rfc_encode"应 为NULL或有效的回调
PHP Warning: array_map(): The first argument, '$this->rfc_encode', should be either NULL or a valid callback
请有人帮我解决这个问题.
Please could anybody help me to fix this.
推荐答案
查看全文