Passing an instance method as argument in PHP

前端 未结 3 1966
我寻月下人不归
我寻月下人不归 2020-12-03 13:29

I would like to create a Listener class

class Listener {
    var $listeners = array();
    
    public function add(callable $function) {
        $this->li         


        
3条回答
  •  旧巷少年郎
    2020-12-03 13:56

    I don't think you can specify a callable this way...

    Try

    $listener->add(array($this, 'bar'));
    

    And see http://php.net/manual/en/language.types.callable.php too.

提交回复
热议问题