Skip to content

Instantly share code, notes, and snippets.

@antoniofrignani
Created July 13, 2016 13:32
Show Gist options
  • Save antoniofrignani/43b5c03efc2552e8c157c8ec3f93c6ae to your computer and use it in GitHub Desktop.
Save antoniofrignani/43b5c03efc2552e8c157c8ec3f93c6ae to your computer and use it in GitHub Desktop.
Invokable callables as parameters
<?php
class Invokable {
function __invoke(Callable $function, array $params = []) {
if (is_callable($function)) return (call_user_func_array($function, $params));
}
}
$return = new Invokable();
$canTrue = function() {
return true;
};
$canFalse = function() {
return false;
};
$canParam = function($param) {
return $param;
};
$val1 = $return($canTrue);
$val2 = $return($canFalse);
$val3 = $return($canParam, ['1']);
var_dump ($val1, $val2, $val3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment