Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher une fonction PHP

func_get_arg

(PHP 4, PHP 5, PHP 7)

func_get_argReturn an item from the argument list

Description

func_get_arg ( int $arg_num ) : mixed

Gets the specified argument from a user-defined function's argument list.

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

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Parameters

arg_num

The argument offset. Function arguments are counted starting from zero.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Return Values

Returns the specified argument, or FALSE on error.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Changelog

Version Description
5.3.0 This function can now be used in parameter lists.
5.3.0 If this function is called from the outermost scope of a file which has been included by calling include or require from within a function in the calling file, it now generates a warning and returns FALSE.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Errors/Exceptions

Generates a warning if called from outside of a user-defined function, or if arg_num is greater than the number of arguments actually passed.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Examples

Example #1 func_get_arg() example

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

foo(123);
?>

The above example will output:

Number of arguments: 3
Second argument is: 2

Example #2 func_get_arg() example before and after PHP 5.3

test.php
<?php
function foo() {
    include 
'./fga.inc';
}

foo('First arg''Second arg');
?>

fga.inc
<?php

$arg 
func_get_arg(1);
var_export($arg);

?>

Output previous to PHP 5.3:

'Second arg'

Output in PHP 5.3 and later:

Warning: func_get_arg():  Called from the global scope - no function
context in /home/torben/Desktop/code/ml/fga.inc on line 3
false

Example #3 func_get_arg() example of byref and byval arguments

<?php
function byVal($arg) {
    echo 
'As passed     : 'var_export(func_get_arg(0)), PHP_EOL;
    
$arg 'baz';
    echo 
'After change  : 'var_export(func_get_arg(0)), PHP_EOL;
}

function 
byRef(&$arg) {
    echo 
'As passed     : 'var_export(func_get_arg(0)), PHP_EOL;
    
$arg 'baz';
    echo 
'After change  : 'var_export(func_get_arg(0)), PHP_EOL;
}

$arg 'bar';
byVal($arg);
byRef($arg);
?>

Output of the above example in PHP 7:


As passed : 'bar'
After change : 'baz'
As passed : 'bar'
After change : 'baz'

Output of the above example in PHP 5:


As passed : 'bar'
After change : 'bar'
As passed : 'bar'
After change : 'baz'

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Notes

Note:

Because this function depends on the current scope to determine parameter details, it cannot be used as a function parameter in versions prior to 5.3.0. If this value must be passed, the results should be assigned to a variable, and that variable should be passed.

Note:

If the arguments are passed by reference, any changes to the arguments will be reflected in the values returned by this function. As of PHP 7 the current values will also be returned if the arguments are passed by value.

Note: This function returns a copy of the passed arguments only, and does not account for default (non-passed) arguments.

Zoek een PHP-functie

Vertaling niet beschikbaar

De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.

Als je de moed voelt, kun je je vertaling aanbieden ;-)

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-function.func-get-arg.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : http://php.net

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut