PHP Closure :: call ()
PHP Closure :: call 7 the () has a better performance, a closure function will dynamically bind to a new object instance and execute the function call.
Examples
Examples
<? php
class A {
private $ x = 1;
}
// Before PHP 7 edition definitions closure function codes
$ getXCB = function () {
return $ this -> x;
};
// Function closure is bound to Class A
$ getX = $ getXCB -> bindTo (new A, 'A');
echo $ getX ();
print (PHP_EOL);
// PHP 7+ Code
$ getX = function () {
return $ this -> x;
};
echo $ getX -> call (new A);
?>
class A {
private $ x = 1;
}
// Before PHP 7 edition definitions closure function codes
$ getXCB = function () {
return $ this -> x;
};
// Function closure is bound to Class A
$ getX = $ getXCB -> bindTo (new A, 'A');
echo $ getX ();
print (PHP_EOL);
// PHP 7+ Code
$ getX = function () {
return $ this -> x;
};
echo $ getX -> call (new A);
?>
The above program execution output is:
1 1