Joh*_*rgo 2 php arrays function
我无法理解代码,这类似于: -
$this->array[$key]($parameter)
为什么会出现($parameter)后$this->array[$key]?
谢谢
作为参考,这里引用的代码片段是以下单行函数:
/**
* Call a custom driver creator.
*
* @param string $name
* @param array $config
* @return mixed
*/
protected function callCustomCreator($name, array $config)
{
return $this->customCreators[$config['driver']]($this->app, $name, $config);
}
Run Code Online (Sandbox Code Playgroud)
保存在该$this->customCreators[$config['driver']]代码段中表示的位置的值是a function.您通常会调用这样的命名函数:
functionName();
Run Code Online (Sandbox Code Playgroud)
打开/关闭括号告诉PHP 调用/执行该函数而不是仅引用它,这意味着您可以将该函数作为参数传递给单独的函数,如下所示:
anotherFunction($this->customCreators[$config['driver']]);
function anotherFunction($creatorFn) {
$creatorFn();
}
Run Code Online (Sandbox Code Playgroud)
PHP 在5.3版本中添加了对lambda样式函数的支持(PHP使用术语"匿名"),这时您可以说我们开始将函数视为一等公民.