php5.3新增闭包函数用法use用法(引入变量地址且随内存中值变化而变化,跳过解析顺序直接获取函数最终值)
$obj = (object) "Hello, everyone";
$callback = function () use ($obj) {
print "This is a closure use object, msg is: {$obj->scalar}. <br />/n";
};
$obj = (object) "Hello, everybody";
callback($callback);
- $msg = "Hello, everyone";
- $callback = function () use (&$msg) {
- print "This is a closure use string value lazy bind, msg is: $msg. <br />/n";
- };
- $msg = "Hello, everybody";
- callback($callback);
时间: 2024-10-08 15:32:07