Hacker Newsnew | comments | show | ask | jobs | submit login

I'm not sure I understand the underlying problem, but apparently you want $delegate->doSomethinWithClosure() to invoke the closure from the context of the current MyClass instance?

So here's how you could solve this "problem" before bindTo(), it's explicit and simple and it doesn't even need use:

  class SomeDelegateClass {
     
    function doSomethingWithClosure($callerObj, $closure) {
      $closure($callerObj);
    }
     
  }

  class MyClass {

    function hello() { print('hello from MyClass!'); }

    function doSomething() {

      $delegate = new SomeDelegateClass();
      $delegate->doSomethingWithClosure($this, function($myClassObj) {
          $myClassObj->hello();
        });

    }
    
  }



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: