时间:2021-07-01 10:21:17 帮助过:23人阅读
一直以为,return只能出现在函数中,直到看了bbPress的代码:
- <?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.gxlcms.com
- return;
- }
难道 return 还能出现在函数之外?这在C语言是无法想象的。
查了一下 PHP 手册:如果在一个函数中调用 return 语句,将立即结束此函数的执行并将它的参数作为函数的值返回。如果在全局范围中调用,则当前脚本文件中止运行。