Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip the rest of the (included) file in PHP

Tags:

include

php

I'm including file inner.php in outer.php, I have a condition in inner.php on which I want to stop executing inner.php but NOT the whole script, i.e. I want to jump to the first line in outer.php after the inclusion of inner.php, and I don't want to wrap all of the code in inner.php in an if statement.

Is there a way to do this otherwise?

like image 334
MeLight Avatar asked May 26 '11 09:05

MeLight


1 Answers

Just do return; or return($value); on top level of the inner.php file.

If called from the global scope, then execution of the current script file is ended. If the current script file was include()ed or require()ed, then control is passed back to the calling file. Furthermore, if the current script file was include()ed, then the value given to return() will be returned as the value of the include() call.

like image 105
vartec Avatar answered Oct 26 '22 18:10

vartec