<code class="lang-php">$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"); </code>
这个hooks function里面有一个use是怎么回事?
想不通。。。。望大师告知
<code class="lang-php">$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"); </code>
这个hooks function里面有一个use是怎么回事?
想不通。。。。望大师告知
5.3 新增的闭包语法中,use 用来捕捉变量到匿名函数内,见:
http://www.php.net/manual/zh/functions.anonymous.php
http://www.cnblogs.com/melonblog/archive/2013/05/01/3052611.html