I am a experience developer in PHP, I already know what is a function and what is a anonymous function. I also know what is the use of anonymous function and functions in PHP or in other languages. I also know the difference between function and anonymous functions.
Defination of anynonymous function is available at: http://php.net/manual/en/functions.anonymous.php
I got the use cases of anonymous function here: Why and how do you use anonymous functions in PHP?
But My question is how does PHP interpret/evaluate functions as arguments?
Consider below example:
<?php
function callFunction($function)
{
$function();
}
//normal function
function test()
{
echo "here";
}
//anonymous function
$function = function () {
echo 'here';
};
//call normal function test
callFunction('test');
//call anonymous function $function
callFunction($function);
In above example both function are producing same output.
But I want to know how PHP execute/interpret/evaluate both functions in callFunction
method. I researched on search engins for the same but unable to found exact answer which can explain the same correctly. Please help me to understand these two cases.