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.