获取可变长度参数
<?php
function check_func()
{
var_dump(func_get_args());
//输出:['www','check','net'];
echo func_get_arg(1),"<br>";
//输出:check
echo func_num_args();
//输出:3
}
check_func("www", "check", "net");
匿名函数
将函数名的字符串赋值给变量,变量加上括号就可以执行.
use引用外部变量
<?php
$str = "this_is_str";
$num = 666;
$a = function () use ($str,&$num)
{
echo $str;
echo $num;
var_dump(func_get_args());
};
$a("www", "check", "net");
类型约束:出参入参
<?php
function text_out_para(int $num):int
{
return $num;
}
echo text_out_para(111);//111
echo text_out_para("eee");
//Argument 1 passed to text_out_para() must be of the type int;
//Argument 1 passed to text_out_para() must be of the type int