Skip to content

Instantly share code, notes, and snippets.

@gooh
Last active December 13, 2015 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gooh/4957242 to your computer and use it in GitHub Desktop.
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.
<?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