Created
February 9, 2012 14:18
-
-
Save mehlah/1780286 to your computer and use it in GitHub Desktop.
PHP 5.4 bindable closures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo | |
{ | |
function barfoo() | |
{ | |
return __FUNCTION__; | |
} | |
function bar() | |
{ | |
return __FUNCTION__; | |
} | |
} | |
$method = 'bar'; | |
$closure = function () use (&$method) { return $this->$method(); }; | |
$c = Closure::bind($closure, new Foo); | |
echo $c(); //bar | |
$method = 'barfoo'; | |
echo $c(); //barfoo | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment