Created
February 16, 2012 18:20
-
-
Save MrMaksimize/1846845 to your computer and use it in GitHub Desktop.
closure
This file contains hidden or 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 | |
$somefunction = function($foo, $bar){ | |
//do something | |
} | |
$myfunction = ($somefunction($foo, $bar), $variable){ | |
//do stuff | |
//call somefunction | |
//do some more stuff | |
} |
You could do:
<?php
$somefunction = function($foo, $bar){
//do something
}
$myfunction = function($function, $variable){
$result = $function('foo', 'bar');
//do stuff
//call somefunction
//do some more stuff
}($somefunction, $variable)
Ooops, I wrote my comment in javascript. In PHP, I am not sure why you can't just do this then...
function my_function($foo, $bar) {
}
$callback = 'my_function';
if (function_exists($callback)) {
$callback('foo', 'bar');
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe this...