Source of: /manual/en/function.return.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.control-structures.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.return.php',
1 => 'return',
),
'up' =>
array (
0 => 'language.control-structures.php',
1 => 'Control Structures',
),
'prev' =>
array (
0 => 'control-structures.declare.php',
1 => 'declare',
),
'next' =>
array (
0 => 'function.require.php',
1 => 'require',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.return" class="sect1">
<h2 class="title">return</h2>
<p class="simpara">
If called from within a function, the <b>return()</b>
statement immediately ends execution of the current function, and
returns its argument as the value of the function
call. <b>return()</b> will also end the execution of
an <a href="function.eval.php" class="function">eval()</a> statement or script file.
</p>
<p class="simpara">
If called from the global scope, then execution of the current
script file is ended. If the current script file was
<a href="function.include.php" class="function">include()</a>ed or <a href="function.require.php" class="function">require()</a>ed,
then control is passed back to the calling file. Furthermore, if
the current script file was <a href="function.include.php" class="function">include()</a>ed, then
the value given to <b>return()</b> will be returned as
the value of the <a href="function.include.php" class="function">include()</a> call. If
<b>return()</b> is called from within the main script
file, then script execution ends. If the current script file was
named by the <a href="ini.core.php#ini.auto-prepend-file" class="link">auto_prepend_file</a> or <a href="ini.core.php#ini.auto-append-file" class="link">auto_append_file</a>
configuration options in <var class="filename">php.ini</var>,
then that script file's execution is ended.
</p>
<p class="simpara">For more information, see <a href="functions.returning-values.php" class="link">Returning values</a>.
</p>
<p class="para">
</p><blockquote><p><b class="note">Note</b>:
<span class="simpara">
Note that since <b>return()</b> is a language
construct and not a function, the parentheses surrounding its
arguments are not required. It is common to leave them out, and you
actually should do so as PHP has less work to do in this case.
</span>
</p></blockquote><p>
</p><blockquote><p><b class="note">Note</b>:
<span class="simpara">
If no parameter is supplied, then the parentheses must be omitted
and <i>NULL</i> will be
returned. Calling <b>return()</b> with parentheses but
with no arguments will result in a parse error.
</span>
</p></blockquote><p>
</p><blockquote><p><b class="note">Note</b>:
<span class="simpara">
You should <em class="emphasis">never</em> use parentheses around your return
variable when returning by reference, as this will not work. You can
only return variables by reference, not the result of a statement. If
you use <i>return ($a);</i> then you're not returning a
variable, but the result of the expression <i>($a)</i>
(which is, of course, the value of <var class="varname">$a</var>).
</span>
</p></blockquote><p>
</p>
</div><?php manual_footer(); ?>