Alternative uses of PHP return statement are not only in functions, return statement_PHP tutorial

WBOY
Release: 2016-07-13 10:18:41
Original
1153 people have browsed it

Alternative usage of PHP return statement is not only in functions, return statement

Share another function of the PHP return statement, a strange usage method seen in the bbPress code.

I always thought that return can only appear in functions, until I looked at the bbPress code:

<&#63;php
require_once('./bb-load.php');

bb_repermalink(); // The magic happens here.

if ( $self ) {
if ( strpos($self, '.php') !== false ) {
require($self);
} else {
require( BB_PATH . 'profile-base.php' );
} // www.jb51.net
return;
}
Copy after login

Can return still appear outside a function? This is unimaginable in C language.

Check the PHP manual: If you call the return statement in a function, it will immediately end the execution of this function and return its parameters as the value of the function. If called in the global scope, the current script file aborts running.

Problems encountered when using the return statement in PHP

return means return.
echo is output. You can also print
return is not output,

For the problem of return statement in php function

Yes, according to the logical relationship, when a return is executed, the following statements will no longer be executed. If one of them is not executed, the following statements may be executed
But in this program The second return is useless and will never be executed

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/880264.htmlTechArticleAlternative uses of the PHP return statement are not only in functions. The return statement shares another function of the PHP return statement. A strange usage method seen in bbPress code. I always thought...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!