Skip to content

Instantly share code, notes, and snippets.

@mehlah
Created February 9, 2012 14:18
Show Gist options
  • Save mehlah/1780286 to your computer and use it in GitHub Desktop.
Save mehlah/1780286 to your computer and use it in GitHub Desktop.
PHP 5.4 bindable closures
<?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