Advertisement
freephile

Rebinding $this

Feb 22nd, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.35 KB | None | 0 0
  1.  
  2. class foo {
  3.   public function getClosure() {
  4.     return function() {
  5.       echo $this->hello;
  6.       $this->world();
  7.     };
  8.   }
  9. }
  10.  
  11. class bar {
  12.   public $hello = "Hello ";
  13.   private function world() { echo "World"; }
  14. }
  15.  
  16. $foo = new Foo();
  17. $closure - $foo->getClosure();
  18. $bar = new Bar();
  19.  
  20. $newClosure = $closure->bindTo($bar);
  21. $newClosure();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement