function &foo( )这样写什么意思?


看到一段程序,方法这样定义,function &foo(),这是神马意思,这里引用有什么用?

   
  function &m($model_name, $params = array(), $is_new = false)
  
{
static $models = array();
$model_hash = md5($model_name . var_export($params, true));
if ($is_new || !isset($models[$model_hash]))
{
$model_file = ROOT_PATH . '/includes/models/' . $model_name . '.model.php';
if (!is_file($model_file))
{
/* 不存在该文件,则无法获取模型 */
return false;
}
include_once($model_file);
$model_name = ucfirst($model_name) . 'Model';
if ($is_new)
{
return new $model_name($params, db());
}
$models[$model_hash] = new $model_name($params, db());
}

return $models[$model_hash];
}

编程语言 php

kasim28 10 years, 10 months ago

在参数前面加“&”符号是自定义函数引用传递。
意思就是不用在里面做全局函数定义就可以直接使用外层函数。

east000 answered 10 years, 10 months ago

Your Answer