Skip to content

Closures and Anonymous Functions #59

@WyrdNexus

Description

@WyrdNexus

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions