发现函数来自TP5
/**
* 命名范围
* @access public
* @param string|array|Closure $name 命名范围名称 逗号分隔
* @param mixed ...$params 参数调用
* @return Model
*/
public static function scope($name)
{
if ($name instanceof Query) {
return $name;
}
$model = new static();
$params = func_get_args();
$params[0] = $model->db();
if ($name instanceof Closure) {
call_user_func_array($name, $params);
} elseif (is_string($name)) {
$name = explode(',', $name);
}
if (is_array($name)) {
foreach ($name as $scope) {
$method = 'scope' . trim($scope);
if (method_exists($model, $method)) {
call_user_func_array([$model, $method], $params);
}
}
}
return $model;
}}
以下介绍来自:http://blog.sina.com.cn/s/blog_816cdc2301014rvt.html
func_get_args是获取方法中参数的数组,返回的是一个数组,
func_num_args一般写在方法中,用于计数;
使用方法如下:
function foo($a='gg',$b='kk'){
$numargs = func_num_args();
echo "Number of arguments: $numargs<br
/>
";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "<br /> ";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "<br /> ";
}
}
foo(1, 2);
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "<br /> ";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "<br /> ";
}
}
foo(1, 2);
输出内容为:
Number of arguments: 2
Second argument is: 2
Argument 0 is: 1
Argument 1 is: 2
Number of arguments: 2
Second argument is: 2
Argument 0 is: 1
Argument 1 is: 2