Difference between "use" and passing a parameter to controller function
This has nothing to do with silex and everything to do with "some new-ish PHP features".
You are creating an anonymous function (also called a closure), reusable several times with different $app
and $id
values, BUT with only the same $blogPosts
value.
<?php
$a = "a";
$b = "b";
$c = function ($d) use ($b) {
echo $d . "." . $b . PHP_EOL;
};
$b = "c";
$e = function ($d) use ($b) {
echo $d . "." . $b . PHP_EOL;
};
$c($a); // prints a.b, and not a.c
$e($a); // prints a.c
Here, i'm building a function with $b, and once it is build, I use it with variables that do not have to be named the same way the function's argument is named.