Skip to content

Instantly share code, notes, and snippets.

@webbower
Created June 24, 2014 22:30
Show Gist options
  • Save webbower/03cc881e6289fa1f3e18 to your computer and use it in GitHub Desktop.
Save webbower/03cc881e6289fa1f3e18 to your computer and use it in GitHub Desktop.
Functional utility function to wrap a declared function in a passable variable for chaining (PHP 5.3- version)
function lambdafy($funcname) {
if (function_exists($funcname)) {
return function() use ($funcname) {
return call_user_func_array($funcname, func_get_args());
};
}
throw new ErrorException('Catchable fatal error: Argument 1 passed to lambdafy() must be callable, string given', E_RECOVERABLE_ERROR);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment