I have a php file, say include.php which has the following contents:
<?php
$myVar = "foo";
?>
Now, I want to create a class, called GlobalInclude, which can include a file in the global scope:
class GlobalInclude {
public function include( $file="include.php" ) {
#do something smart
include $file
#do something smart
}
}
In it’s current form, the $myVar variable will only be available inside the scope of the include function. I want to do something like:
GlobalInclude::include( "include.php" );
echo $myVar;
Output
foo
Any ideas on how I can accomplish this?
Thought I’d update the answer here.
I wrapped my app entry in a try catch, and threw a
IncludeInGlobalExceptionwith the file name as the message. Then, in the catch block, I included the file.