Last active
December 8, 2015 18:38
-
-
Save quickshiftin/01da6e4f22e34c01b9a6 to your computer and use it in GitHub Desktop.
Syntactic sugar to quickly create a closure for an instance method. Especially useful for creating 'callables' to private methods.
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 NNReflectionMethod extends ReflectionMethod | |
{ | |
static public function closure($object, $method) | |
{ | |
if(!is_object($object)) { | |
throw new InvalidArgumentException('$object must be an object'); | |
} | |
$oRm = new ReflectionMethod($object, $method); | |
return $oRm->getClosure($object); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the blog article here for the full writeup!