Home > Backend Development > PHP Tutorial > php-return statement

php-return statement

伊谢尔伦
Release: 2016-11-24 09:13:03
Original
1172 people have browsed it

If the return statement is called in a function, the execution of this function will be ended immediately and its parameters will be returned as the value of the function. return will also terminate the execution of the eval() statement or script file.

If called in the global scope, the current script file aborts running. If the current script file is included or required, control is returned to the calling file. In addition, if the current script is included, the return value will be treated as the return value of the include call. If return is called in the main script file, the script aborts. If the current script file is specified by the configuration option auto_prepend_file or auto_append_file in php.ini, the script file stops running.

Note: Note that since return is a language structure rather than a function, there is no need to enclose its parameters in parentheses. Parentheses are usually not used, and in fact they should be, to reduce the load on PHP.

Note: If no parameters are provided, parentheses must not be used, and NULL will be returned. If return is called with parentheses but no parameters, a parsing error will occur.

Note: Never use parentheses when returning a value by reference, it won't work. Variables can only be returned by reference, not the result of a statement. If you use return ($a);, it does not actually return a variable, but the value of the expression ($a) (of course, the value is also the value of $a at this time).


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template