<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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',
    2 => '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',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/control-structures/return.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.return" class="sect1">
 <h2 class="title">return</h2>
 <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p>
 <p class="simpara">
  <code class="literal">return</code> returns program control to the calling module.
  Execution resumes at the expression following the called module&#039;s invocation.
 </p>
 <p class="simpara">
  If called from within a function, the <code class="literal">return</code>
  statement immediately ends execution of the current function, and
  returns its argument as the value of the function
  call. <code class="literal">return</code> also ends the execution of
  an <span class="function"><a href="function.eval.php" class="function">eval()</a></span> 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
  <span class="function"><a href="function.include.php" class="function">include</a></span>d or <span class="function"><a href="function.require.php" class="function">require</a></span>d,
  then control is passed back to the calling file. Furthermore, if
  the current script file was <span class="function"><a href="function.include.php" class="function">include</a></span>d, then
  the value given to <code class="literal">return</code> will be returned as
  the value of the <span class="function"><a href="function.include.php" class="function">include</a></span> call. If
  <code class="literal">return</code> 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&#039;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">
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Note that since <code class="literal">return</code> is a language
    construct and not a function, the parentheses surrounding its
    argument are not required and their use is discouraged.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    If no parameter is supplied, then the parentheses must be omitted
    and <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> will be
    returned. Calling <code class="literal">return</code> with parentheses but
    with no arguments will result in a parse error.
   </span>
  </p></blockquote>
 </p>

 <p class="para">
  As of PHP 7.1.0, return statements without an argument in functions which declare a return type trigger <strong><code><a href="errorfunc.constants.php#constant.e-compile-error">E_COMPILE_ERROR</a></code></strong>,
  unless the return type is <span class="type"><span class="type"><a href="language.types.void.php" class="type void">void</a></span></span>, in which case return statements
  with an argument trigger that error.
 </p>
</div><?php manual_footer($setup); ?>