Last active
December 13, 2015 18:39
-
-
Save gooh/4957242 to your computer and use it in GitHub Desktop.
Code to turn all defined internal functions into Closures to be able to pass them around as First Class Citizens. Not that you should do that.
This file contains 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 | |
$functions = get_defined_functions(); | |
foreach($functions['internal'] as $function) { | |
$GLOBALS[$function] = function() use ($function) { | |
return call_user_func_array( | |
$function, | |
func_get_args() | |
); | |
}; | |
} | |
// Alternate version (PHP >= 5.4) | |
foreach (get_defined_functions()['internal'] as $function) { | |
$GLOBALS[$function] = (new ReflectionFunction($function))->getClosure(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment