Home > Backend Development > PHP Tutorial > PHP return语句另类用法不止是在函数中_php技巧

PHP return语句另类用法不止是在函数中_php技巧

WBOY
Release: 2016-05-16 20:35:58
Original
1172 people have browsed it

分享下PHP return语句的另一个作用,在bbPress的代码中看到的一个奇葩使用方法。

一直以为,return只能出现在函数中,直到看了bbPress的代码:

<&#63;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;
}
Copy after login

难道 return 还能出现在函数之外?这在C语言是无法想象的。

查了一下 PHP 手册:如果在一个函数中调用 return 语句,将立即结束此函数的执行并将它的参数作为函数的值返回。如果在全局范围中调用,则当前脚本文件中止运行。

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