PHP7中Closure :: call使用示例
- Closure :: call - 绑定并调用闭包
- Closure :: bind - 使用特定的绑定对象和类范围复制一个闭包
与 PHP5.6 的 bindTo 相比,PHP7 中的 Closure :: call()方法具有更好的性能,该方法被添加为临时将对象范围绑定到闭包并调用它。
较早的 PHP 示例:
x;
};
// Bind a clousure
$value = $getValue->bindTo(new A, 'A');
print($value());
?>
它产生以下浏览器输出:
1
PHP7 及以上版本示例:
x;
};
print($value->call(new A));
?>
它产生以下浏览器输出:
1