Wednesday, 20 February 2019

PHP annmous function

PHP annymous function use global var
// No "use"$example = function () {
    
var_dump($message);
};
$example();
// Inherit $message$example = function () use ($message) {
    
var_dump($message);
};
$example();

Notice: Undefined variable: message in /example.php on line 6
NULL
string(5) "hello"
http://php.net/manual/en/functions.anonymous.php

No comments:

Post a comment