Anonymous features are also known as Closures .
You ask where $y gets its value. The sample code is hard to decrypt, because you use 2s and 3s everywhere. Everything will be clearer if your last lines were
$a = z(2); $b = z(3); echo $a('A').$b('B');
This will lead to:
AABBB
But let your code follow. Note that there are two related function calls
$a = z(2);
and
echo $a(3);
the calling function z() with argument 2 returns a function (which is assigned the name $a ), where the string
return str_repeat($y, $x);
in reality:
return str_repeat($y, 2);
now you call this function $a() with argument 3. That 3 (the value of $y ) is repeated twice
The same analysis applies to other related function calls:
$b = z(3); ... echo ... $b(2);
But in this case 2 is repeated 3 times
source share