The func_get_arg() function is an inbuilt function in PHP which is used to get a mentioned value from the argument passed as the parameters.
Syntax:
mixed func_get_arg( int $arg )
Parameters: This function accepts a single parameter as mentioned above and described below.
- $arg: This parameter holds the argument offset where the offset of the arguments in the parameter is counted by assuming the first argument to be 0.
Return Value: This method returns the mentioned argument and returns FALSE if an error occurs.
Example 1:
| <?php  Â// Function definition functionneveropen($a, $b, $c) {  Â    // Calling func_get_arg() function       echo"Print second argument: "        . func_get_arg(1) . "\n"; }  Â// Function call neveropen('hello', 'php', 'neveropen');  Â?>  | 
Output:
Print second argument: php
When does any error occur?
The error occurs in two cases.
- If the value of argument offset is more than the actual value of arguments passed as the parameter of the function.
- If this function is not being called from within the user-defined function.
| <?php  Â// Function definition functionneveropen($a, $b, $c) {  Â    // Printing the sixth argument     // that doesn't exist     echo"Printing the sixth argument: "        . func_get_arg(5) . "\n"; }  Â// Function call neveropen('hello', 'php', 'neveropen');  Â?>  | 
Output:
Warning:  func_get_arg():  Argument 5 not passed to function in 
    [...][...] on line 4
Example:
| <?php  Â// Function definition functionneveropen($a, $b, $c) {      $a= "Bye"; }  Â// Function call neveropen('hello', 'php', 'neveropen');  Â// The func_get_arg() function // is called from outside the // user defined function echo"Printing the sixth argument: "        . func_get_arg(5) . "\n";          Â?>  | 
Output:
PHP Warning: func_get_arg(): Called from the global scope - no function context in /home/main.php on line 9
For versions before PHP 5.3: Getting a function’s argument has a different approach for the PHP versions below 5.3. All the versions above 5.3 and 5.3 will show an error for the following code.
Example:
| <?php functionneveropen() {     include'./testing.inc'; }  Âneveropen('Welcome', 'PHP', 'Geeks'); ?>  | 
testing.inc:
| <?php  Â$parameter= func_get_arg(1); var_export($parameter);  Â?>  | 
Output:
'PHP' warnings
Note: For getting more than one argument func_get_args() function can be used instead of func_get_arg() function.


 
                                    







