Alternative usage of PHP return statement, alternative usage of phpreturn statement_PHP tutorial

WBOY
Release: 2016-07-13 10:21:35
Original
904 people have browsed it

Alternative usage of PHP return statement, alternative usage of phpreturn statement

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>
Copy after login

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.

Problems encountered when using the return statement in PHP

return means return.
echo is output. You can also print
return is not output,

For the problem of return statement in php function

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/854730.htmlTechArticleAlternative usage of PHP return statement, alternative use of phpreturn statement Share another function of PHP return statement in bbPress code I saw a weird way to use it. I always thought that return 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