-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
Closures and Anonymous Functions Affect a Syntax Error
Any attempt to create a callback function, anonymous function, or wrapper, generates a syntax error.
http://php.net/manual/en/functions.anonymous.php
Anonymous Function Syntax Errors
// Case 1:
$fn = function($e) { // Undefined is not a function on line NaN
echo $e;
}
$fn("hello\n");
// Case 2:
function callme($str, $func) {
$func($str);
}
callme( "maybe", function($e) { // Undefined is not a function on line NaN
echo $e . "\n";
} );
// Case 3:
echo preg_replace_callback('~-([a-z])~', function ($match) { // Undefined is not a function on line NaN
return strtoupper($match[1]);
}, 'hello-world');Output:
hello
maybe
hello-world
Metadata
Metadata
Assignees
Labels
No labels