Another function of the PHP return statement

  • 2021-07-10 18:58:18
  • OfStack

1 Think that return can only appear in functions until you look at the code for 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' );
 }
 return;
}

Can return still appear outside the function? This is unimaginable in C language.

Check 1 PHP manual: If you call return statement in 1 function, it will immediately end the execution of this function and return its parameters as the value of the function. If called in global scope, the current script file stops running.

Alas, it is too poisoned by C language.


Related articles: