I would like to create a Listener class
class Listener {
    var $listeners = array();
    
    public function add(callable $function) {
        $this->listeners[] = $function;
    }
    public function fire() {
        foreach($this->listeners as $function) {
            call_user_func($function);
        }
    }
}
class Foo {
    public function __construct($listener) {
        $listener->add($this->bar);
    }
    
    public function bar() {
        echo 'bar';
    }
}
$listener = new Listener();
$foo = new Foo($listener);
But this code fails with this error:
Notice: Undefined property: Foo::$bar in index.php on line 18
Catchable fatal error: Argument 1 passed to Listener::add() must be callable, null given, called in index.php on line 18 and defined index.php on line 5
What am I doing wrong?
 
     
     
     
    