Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closures and Anonymous Functions #59

Open
WyrdNexus opened this issue Sep 18, 2014 · 0 comments
Open

Closures and Anonymous Functions #59

WyrdNexus opened this issue Sep 18, 2014 · 0 comments

Comments

@WyrdNexus
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant