Home > Article > Backend Development > Alternative uses of PHP return statement are not only in functions, return statement_PHP tutorial
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:
<?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; }
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.
return means return.
echo is output. You can also print
return is not output,
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