Home  >  Article  >  php教程  >  PHP return语句另类用法不止是在函数中

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

WBOY
WBOYOriginal
2016-06-13 09:25:121694browse

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

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

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

  

  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;

  }

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

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

Statement:
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