Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return from include file

Tags:

php

in PHP, how would one return from an included script back to the script where it had been included from?

IE:

1 - main script 2 - application 3 - included

Basically, I want to get back from 3 to 2, return() doesn't work.

Code in 2 - application

$page = "User Manager"; if($permission["13"] !=='1'){     include("/home/radonsys/public_html/global/error/permerror.php");     return(); } 
like image 521
bear Avatar asked Aug 21 '09 20:08

bear


People also ask

What is include () function used for?

The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

How do I return a PHP file?

The return keyword ends a function and, optionally, uses the result of an expression as the return value of the function. If return is used outside of a function, it stops PHP code in the file from running.

What is __ DIR __ in PHP?

The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.

What does Include_once mean in PHP?

The include_once keyword is used to embed PHP code from another file. If the file is not found, a warning is shown and the program continues to run. If the file was already included previously, this statement will not include it again.


1 Answers

includeme.php:

$x = 5; return $x; 

main.php:

$myX = require 'includeme.php';  

also gives the same result

This is one of those little-known features of PHP, but it can be kind of nice for setting up really simple config files.

like image 195
Frank Farmer Avatar answered Oct 04 '22 06:10

Frank Farmer