What I am trying to achieve is this:
$x = 5;
$b = function ($x) {
echo 'This should be 5 :' . $x;
};
function a($fn){
echo 'In a ';
$fn();
}
a($b);
That when you run this code, we get
In a
This should be 5 :5
What we get instead is
Warning: Missing argument 1 for {closure}(), called in writecodeonline.com/php on line 10 and defined on line 3 This should be 5
I don't want to redefine the argument I already defined
What I don't want neither is hide the $x. I don't want to change its visibility.
Is there a way for this?