Skip to content

Instantly share code, notes, and snippets.

@jm42
Created December 13, 2015 19:20
Show Gist options
  • Save jm42/7f61fcf14819955e79f2 to your computer and use it in GitHub Desktop.
Save jm42/7f61fcf14819955e79f2 to your computer and use it in GitHub Desktop.
Match and call... match and call.
<?php
function match() {
func_num_args() or die('Remember the milk?');
$fnm = function() { return true; };
$fns = func_get_args();
if (is_string($match = func_get_arg(0))) {
$fnm = function() use($match) {
return $match === '/';
};
$fns = array_slice($fns, 1);
}
return function() use($fnm, $fns) {
if (call_user_func($fnm)) {
foreach ($fns as $fn) {
call_user_func($fn);
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment