Home >Backend Development >PHP Tutorial >Alternative uses of PHP return statement not only in functions_PHP Tutorial

Alternative uses of PHP return statement not only in functions_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:18:411002browse

The alternative usage of PHP return statement is not only in functions

Let me share another function of PHP return statement, a strange usage method seen in bbPress code.

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

 

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;

 }

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

I checked the PHP manual: If the return statement is called in a function, the execution of the function will be ended immediately and its parameters will be returned as the value of the function. If called in the global scope, the current script file aborts running.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/880147.htmlTechArticleAlternative usage of PHP return statement is not only to share another function of PHP return statement in functions, but also in bbPress code A strange usage method I saw in . I always thought that return can only...
Statement:
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