时间:2021-07-01 10:21:17 帮助过:20人阅读
$hooks = function($meta, $type) use ($inspector, $instance)
{
if (isset($meta[$type]))
{
$run = array();
foreach ($meta[$type] as $method)
{
$hookMeta = $inspector->getMethodMeta($method);
if (in_array($method, $run) && !empty($hookMeta["@once"]))
{
continue;
}
$instance->$method();
$run[] = $method;
}
}
};
$hooks($methodMeta, "@before");
这个hooks function里面有一个use是怎么回事?
想不通。。。。望大师告知
$hooks = function($meta, $type) use ($inspector, $instance)
{
if (isset($meta[$type]))
{
$run = array();
foreach ($meta[$type] as $method)
{
$hookMeta = $inspector->getMethodMeta($method);
if (in_array($method, $run) && !empty($hookMeta["@once"]))
{
continue;
}
$instance->$method();
$run[] = $method;
}
}
};
$hooks($methodMeta, "@before");
这个hooks function里面有一个use是怎么回事?
想不通。。。。望大师告知
5.3 新增的闭包语法中,use 用来捕捉变量到匿名函数内,见:
http://www.php.com/manual/zh/functions.anonymous.php
http://www.cnblogs.com/melonblog/archive/2013/05/01/3052611.html