超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<create_functionfunc_get_args>
Last updated: Fri, 22 Jun 2007

func_get_arg

(PHP 4 , PHP 5)

func_get_arg -- Return an item from the argument list

Description

mixed func_get_arg ( int arg_num)

Returns the argument which is at the arg_num'th offset into a user-defined function's argument list. Function arguments are counted starting from zero. func_get_arg() will generate a warning if called from outside of a function definition. This function cannot be used directly as a function parameter. Instead, its result may be assigned to a variable, which can then be passed to the function.

If arg_num is greater than the number of arguments actually passed, a warning will be generated and func_get_arg() will return FALSE.

<?php
function foo()
{
    
$numargs = func_num_args();
     echo
"Number of arguments: $numargs<br />\n";
     if (
$numargs >= 2) {
     echo
"Second argument is: " . func_get_arg(1) . "<br />\n";
     }
}

foo (1, 2, 3);
?>

func_get_arg() may be used in conjunction with func_num_args() and func_get_args() to allow user-defined functions to accept variable-length argument lists.




add a note add a note User Contributed Notes
func_get_arg
martin at classaxe dot com
08-Jun-2002 01:55
This function whilst elegant doesn't in itself avoid the problem of generating warning messages where variables are not set, unless of course you switched warnings off:
error_reporting(E_ERROR);

The answer for those of who like to see necessary warnings?
Call it like this:
@allSet($w, $x, $y, $z)

(Martin Francis)

<create_functionfunc_get_args>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22