title: Passing an instance method as argument in PHP
body: <p>I would like to create a Listener class</p>
  <pre><code>class Listener {
      var $listeners = array();
      
      public function add(callable $function) {
          $this-&gt;listeners[] = $function;
      }
  
      public function fire() {
          foreach($this-&gt;listeners as $function) {
              call_user_func($function);
          }
      }
  }
  
  class Foo {
      public function __construct($listener) {
          $listener-&gt;add($this-&gt;bar);
      }
      
      public function bar() {
          echo 'bar';
      }
  }
  
  
  
  $listener = new Listener();
  $foo = new Foo($listener);
  </code></pre>
  <p>But this code fails with this error:</p>
  <blockquote>
  <p>Notice: Undefined property: Foo::$bar in index.php on line 18</p>
  <p>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</p>
  </blockquote>
  <p>What am I doing wrong?</p>