What is $data? What you have shown here is just a definition of a parameter your anonymous function is expecting, but you don't have it anywhere inside the body of the doIt() function that's actually using it. That's what the error is telling you. If you have $data defined inside doIt(), everything shall work as expected.
NOTICE Undefined variable: data on line number 7
WARNING Missing argument 1 for {closure}(), called in /home4/phptest/public_html/code.php70(5) : eval()'d code on line 4 and defined on line number 7
Anonymous function!
Code:
function doIt($callback) {
$callback();
}
doIt(function($data) use ($data) {
echo 'Anonymous function!' . $data;
});
@SNAPEY - I got it to work. However I have seen code without the use keyword like this. How do they do it?
function doIt($callback) {
$callback();
}
$data = 'my data here...';
doIt(function($data) {
echo 'Anonymous function!' . $data;
});
This is giving me these errors:
WARNING Missing argument 1 for {closure}(), called in /home4/phptest/public_html/code.php70(5) : eval()'d code on line 4 and defined on line number 9
NOTICE Undefined variable: data on line number 10