func_get_arg报错
有时,在使用 func_get_arg() 函数时,可能会发生错误。
下面,我们将考虑可能导致错误的两种主要情况。
- 一旦参数偏移值高于作为函数参数传递的参数的实际值。
- 一旦在用户定义的函数内部没有调用该函数。
下面是一个例子:
<?php //Function definition function onitroad($a, $b, $c) { //Printing the sixth argument //that doesn't exist echo "Printing the sixth argument: " . func_get_arg(5) . "\n"; } //Function call onitroad('hello', 'php', 'onitroad'); ?>
输出将如下所示:
Warning: func_get_arg(): Argument 5 not passed to function in [...][...] on line 4
在 PHP 中,为了从作为参数传递的参数中获取提到的值,我们可以使用内置的 func_get_arg() 函数。
该函数的语法如下所示:
mixed func_get_arg( int $arg )
此函数只能接受一个参数,即 $arg。
func_get_arg 函数在成功时返回上述参数,否则返回 FALSE。
为了清楚起见,我们将演示一个示例:
<?php //Function definition function onitroad($a, $b, $c) { //Call the func_get_arg() function echo "Print second argument: " . func_get_arg(1) . "\n"; } //Function call onitroad('hello', 'php', 'onitroad'); ?>
作为输出,结果如下:
Print second argument: php
日期:2020-06-02 22:15:55 来源:oir作者:oir