How to call callback method for class?

2019-06-11 09:52发布

Help me please:

class xam{

       public static function __callStatic($name, $arguments) {
            self::$name();
        }

        static protected function mycallback(){
            echo 'mycallback';
        }
    }

    function doIt($callback) { $callback(); }

I am trying:

doIt(xam::mycallback);

Error:

Fatal error: Undefined class constant 'mycallback'

I know one variant:

doIt(function(){xam::mycallback();});

But it may have an alternative ? Thanks for your help .

标签: php oop
2条回答
成全新的幸福
2楼-- · 2019-06-11 10:25

You can specify the callback as the string "xam::mycallback" or array ['xam', 'mycallback']. The manual describes all the options for specifying callables.

查看更多
相关推荐>>
3楼-- · 2019-06-11 10:26

Try using this...

doIt('xam::mycallback');
查看更多
登录 后发表回答