downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

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> &mdash; <span class="dc-title">Returns an array comprising a function&#039;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&#039;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&#039;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">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$numargs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">func_num_args</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Number&nbsp;of&nbsp;arguments:&nbsp;</span><span style="color: #0000BB">$numargs</span><span style="color: #DD0000">&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$numargs&nbsp;</span><span style="color: #007700">&gt;=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Second&nbsp;argument&nbsp;is:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">func_get_arg</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$arg_list&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$numargs</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Argument&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #DD0000">&nbsp;is:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$arg_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<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">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</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&lt;br /&gt;
Second argument is: 2&lt;br /&gt;
Argument 0 is: 1&lt;br /&gt;
Argument 1 is: 2&lt;br /&gt;
Argument 2 is: 3&lt;br /&gt;
</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">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;</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&nbsp;arg'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Second&nbsp;arg'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;<br /></span><br />fga.inc<br /><span style="color: #0000BB">&lt;?php<br /><br />$args&nbsp;</span><span style="color: #007700">=&nbsp;</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">?&gt;</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 =&gt; &#039;First arg&#039;,
  1 =&gt; &#039;Second arg&#039;,
)
</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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites