Sometimes while initializing variables, you want to pass them values that are too complex to be computed in a single command, so you usually either compute a dummy variable before and then pass its value, or define a function elsewhere, and pass it's return value to our variable.
My question (wish) is, is it possible instead compute to a variable on the fly using anonymous functions?
for example, instead of use this:
$post = get_post();
$id = $post->ID;
$array = array(
'foo' => 'hi!',
'bar' => $id
);
Lets use something like this:
$array = array(
'foo' => 'hi!',
'bar' => (function(){
$post = get_post();
return $post->ID;
})
);
Code is totaly random.