相关疑难解决方法(0)

如何使用对象方法作为回调函数

我在单例类中有以下方法

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 '';
    }
}
Run Code Online (Sandbox Code Playgroud)

这作为一个普通的功能很好

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 '';
    }
}
Run Code Online (Sandbox Code Playgroud)

当在一个类中使用时,我得到以下错误:

PHP警告:array_map():第一个参数'$ this-> rfc_encode'应该是NULL或有效的回调

请任何人帮我解决这个问题.

php

11
推荐指数
1
解决办法
7230
查看次数

标签 统计

php ×1