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:
<?<span>php </span><span>require_once</span>('./bb-load.php'<span>); bb_repermalink(); </span><span>//</span><span> The magic happens here.</span> <span>if</span> ( <span>$self</span><span> ) { </span><span>if</span> ( <span>strpos</span>(<span>$self</span>, '.php') !== <span>false</span><span> ) { </span><span>require</span>(<span>$self</span><span>); } </span><span>else</span><span> { </span><span>require</span>( BB_PATH . 'profile-base.php'<span> ); } // www.jbxue.com </span><span>return</span><span>; }</span>
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