Alternative uses of PHP return statement not only in functions_PHP Tutorial

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

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...
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