Source of: /manual/en/function.func-get-arg.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-arg.php',
1 => 'func_get_arg',
),
'up' =>
array (
0 => 'ref.funchand.php',
1 => 'Function handling Functions',
),
'prev' =>
array (
0 => 'function.forward-static-call.php',
1 => 'forward_static_call',
),
'next' =>
array (
0 => 'function.func-get-args.php',
1 => 'func_get_args',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.func-get-arg" class="refentry">
<div class="refnamediv">
<h1 class="refname">func_get_arg</h1>
<p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">func_get_arg</span> — <span class="dc-title">Return an item from the argument list</span></p>
</div>
<a name="function.func-get-arg.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b>func_get_arg</b></span>
( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$arg_num</tt></span>
)</div>
<p class="para rdfs-comment">
Gets the specified argument from a user-defined function's argument list.
</p>
<p class="para">
This function may be used in conjunction with
<a href="function.func-get-args.php" class="function">func_get_args()</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-arg.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">arg_num</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The argument offset. Function arguments are counted starting from
zero.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.func-get-arg.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns the specified argument, or <b><tt class="constant">FALSE</tt></b> on error.
</p>
</div>
<a name="function.func-get-arg.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-arg.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, or
if <i><tt class="parameter">arg_num</tt></i>
is greater than the number of arguments
actually passed.
</p>
</div>
<a name="function.func-get-arg.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_arg()</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 />}<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><p>
</p>
<p class="para">
</p><div class="example">
<p><b>Example #2 <b>func_get_arg()</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.php<br /><span style="color: #0000BB"><?php<br /><br />$arg </span><span style="color: #007700">= </span><span style="color: #0000BB">func_get_arg1</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</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>
'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_arg(): 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-arg.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-arg.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-args.php" class="function" rel="rdfs-seeAlso">func_get_args()</a> - Returns an array comprising a function's 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(); ?>