PHP: Pass anonymous function as argument
问题 Is it possible to pass an anonymous function as an argument, and have it execute immediately, thus passing the function's return value? function myFunction(Array $data){ print_r($data); } myFunction(function(){ $data = array( 'fruit' => 'apple', 'vegetable' => 'broccoli', 'other' => 'canned soup'); return $data; }); This throws an error due to the Array type-hint, complaining of an object being passed. Alright, if I remove the type-hint, it of course spits out Closure Object , rather than the