Source of: /manual/en/function.func-get-args.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.funchand.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.func-get-args.php',
1 => 'func_get_args',
),
'up' =>
array (
0 => 'ref.funchand.php',
1 => 'Function handling Functions',
),
'prev' =>
array (
0 => 'function.func-get-arg.php',
1 => 'func_get_arg',
),
'next' =>
array (
0 => 'function.func-num-args.php',
1 => 'func_num_args',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.func-get-args" class="refentry">
<div class="refnamediv">
<h1 class="refname">func_get_args</h1>
<p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">func_get_args</span> — <span class="dc-title">Returns an array comprising a function's argument list</span></p>
</div>
<a name="function.func-get-args.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">array</span> <span class="methodname"><b>func_get_args</b></span>
( <span class="methodparam">void</span>
)</div>
<p class="para rdfs-comment">
Gets an array of the function's argument list.
</p>
<p class="para">
This function may be used in conjunction with
<a href="function.func-get-arg.php" class="function">func_get_arg()</a> and <a href="function.func-num-args.php" class="function">func_num_args()</a>
to allow user-defined functions to accept variable-length argument lists.
</p>
</div>
<a name="function.func-get-args.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns an array in which each element is a copy of the corresponding
member of the current user-defined function's argument list.
</p>
</div>
<a name="function.func-get-args.changelog"></a><div class="refsect1 changelog">
<h3 class="title">Changelog</h3>
<p class="para">
</p><table class="doctable informaltable">
<thead valign="middle">
<tr valign="middle">
<th>Version</th>
<th>Description</th>
</tr>
</thead>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left">5.3.0</td>
<td align="left">
This function can now be used in parameter lists.
</td>
</tr>
<tr valign="middle">
<td align="left">5.3.0</td>
<td align="left">
If this function is called from the outtermost scope of a file
which has been included by calling <a href="function.include.php" class="function">include()</a>
or <a href="function.require.php" class="function">require()</a> from within a function in the
calling file, it now generates a warning and returns <b><tt class="constant">FALSE</tt></b>.
</td>
</tr>
</tbody>
</table>
<p>
</p>
</div>
<a name="function.func-get-args.errors"></a><div class="refsect1 errors">
<h3 class="title">Errors/Exceptions</h3>
<p class="para">
Generates a warning if called from outside of a user-defined function.
</p>
</div>
<a name="function.func-get-args.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <b>func_get_args()</b> example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">foo</span><span style="color: #007700">()<br />{<br /> </span><span style="color: #0000BB">$numargs </span><span style="color: #007700">= </span><span style="color: #0000BB">func_num_args</span><span style="color: #007700">();<br /> echo </span><span style="color: #DD0000">"Number of arguments: </span><span style="color: #0000BB">$numargs</span><span style="color: #DD0000"><br />\n"</span><span style="color: #007700">;<br /> if (</span><span style="color: #0000BB">$numargs </span><span style="color: #007700">>= </span><span style="color: #0000BB">2</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Second argument is: " </span><span style="color: #007700">. </span><span style="color: #0000BB">func_get_arg</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">) . </span><span style="color: #DD0000">"<br />\n"</span><span style="color: #007700">;<br /> }<br /> </span><span style="color: #0000BB">$arg_list </span><span style="color: #007700">= </span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br /> for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">$numargs</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /> echo </span><span style="color: #DD0000">"Argument </span><span style="color: #0000BB">$i</span><span style="color: #DD0000"> is: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$arg_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">] . </span><span style="color: #DD0000">"<br />\n"</span><span style="color: #007700">;<br /> }<br />}<br /><br /></span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents para"><p>The above example will output:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Number of arguments: 3<br />
Second argument is: 2<br />
Argument 0 is: 1<br />
Argument 1 is: 2<br />
Argument 2 is: 3<br />
</pre></div>
</div>
</div><p>
</p>
<p class="para">
</p><div class="example">
<p><b>Example #2 <b>func_get_args()</b> example before and
after PHP 5.3</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
test.php<br /><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">foo</span><span style="color: #007700">() {<br /> include </span><span style="color: #DD0000">'./fga.inc'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #DD0000">'First arg'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Second arg'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?><br /></span><br />fga.inc<br /><span style="color: #0000BB"><?php<br /><br />$args </span><span style="color: #007700">= </span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$args</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents para"><p>
Output previous to PHP 5.3:
</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
array (
0 => 'First arg',
1 => 'Second arg',
)
</pre></div>
</div>
<div class="example-contents para"><p>
Output in PHP 5.3 and later:
</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Warning: func_get_args(): Called from the global scope - no function
context in /home/torben/Desktop/code/ml/fga.inc on line 3
false
</pre></div>
</div>
</div><p>
</p>
</div>
<a name="function.func-get-args.notes"></a><div class="refsect1 notes">
<h3 class="title">Notes</h3>
<blockquote><p><b class="note">Note</b>: Because this function depends on the
current scope to determine parameter details, it cannot be used as a
function parameter. If this value must be passed, the results should be assigned
to a variable, and that variable should be passed.<br /></p></blockquote>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
This function returns a copy of the passed arguments only, and does not
account for default (non-passed) arguments.
</span>
</p></blockquote>
</div>
<a name="function.func-get-args.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.func-get-arg.php" class="function" rel="rdfs-seeAlso">func_get_arg()</a> - Return an item from the argument list</li>
<li class="member"><a href="function.func-num-args.php" class="function" rel="rdfs-seeAlso">func_num_args()</a> - Returns the number of arguments passed to the function</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>