<?php
namespace app\index\controller;
class Demo1
{
//绑定一个闭包容器:闭包现在请理解为一个匿名函数
public function bindClosure()
{
//把一个闭包放到容器中 相当于
/*$demo=function($domain){
return 'PHP中文网的域名是:'.$domain;
};*/
\think\Container::set('demo',function($domain){
return 'PHP中文网的域名是:'.$domain;
});
//将容器中的闭包取出来用
return \think\Container::get('demo',['domain'=>'www.php.cn']);
}
}
}
}