So I have made a custom function that will search in a set location for the file and return it. I include the helper that contains this function and then include a file with variables.
I want to then be able to access these variables in the included files using the function.
Here is my setup:
Main file
<?php
require 'helper.php';
require 'variable.php';
$Helper -> include_asset("text.php");
?>
Helper.php
<?php
function include_asset($file) {
$full_path = "path/to/assets/folder/".$file;
return (file_exists($full_path)) ? include $full_path : "file ".$file." does not exist";
}
?>
variable.php
<?php $text = "hello"; ?>
text.php
<?php echo $text; ?>
Problem is that the variable $text can not be accessed within the included file but can within the main file. I think it has something to do with the include custom function being a function so variable scope but not sure. Any help?