return
return
(PHP 4, PHP 5, PHP 7)
return
return
s program control to the calling module. Execution resumes at the expression following the called module's invocation.
If called from within a function, the return
statement immediately ends execution of the current function, and return
s its argument as the value of the function call. return
also ends the execution of an eval() statement or script file.
If called from the global scope, then execution of the current script file is ended. If the current script file was included or required, then control is passed back to the calling file. Furthermore, if the current script file was included, then the value given to return
will be return
ed as the value of the include call. If return
is called from within the main script file, then script execution ends. If the current script file was named by the auto_prepend_file or auto_append_file configuration options in php.ini, then that script file's execution is ended.
For more information, see Returning values.
Note
:Note
that sincereturn
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.Note
: If no parameter is supplied, then the parentheses must be omitted andNULL
will bereturn
ed. Callingreturn
with parentheses but with no arguments will result in a parse error.Note
: You shouldnever
use parentheses around yourreturn
variable whenreturn
ing by reference, as this will not work. You can onlyreturn
variables by reference, not the result of a statement. If you usereturn ($a t
hen you're notreturn
ing a variable, but the result of the expression ($a) (
which is, of course, the value of $a).
← declare
require →
© 1997–2017 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.