External Variables of Anonymous Functions in PHP
Anonymous functions, just like regular ones, cannot see variables declared outside the function:
<?php
$num1 = 1;
$num2 = 2;
$func = function()
{
echo $num1 + $num2; // error, variables are not accessible
};
$func();
?>
Explain what the result of executing the code will be:
<?php
$num = 5;
$func = function()
{
return $num ** 2;
};
echo $func();
?>