As the title says, the include function is not working in a certain part of my code. As another section of the same file uses "include", I know that it is not an issue with this particular file, it is an issue with how I am trying to include it. I'm just a beginner in PHP so I can't figure out what I'm doing wrong, despite actual hours looking up different solutions and trying them.
It would take too much space to copy over the actual code, so I'm going to do a simpler version of it with just the needed information. The location of file1.php is:
$_SERVER['DOCUMENT_ROOT']."/TAO_3.1.0-RC3_build/taoDelivery/controller/file1.php"
The location of file2.php is:
$_SERVER['DOCUMENT_ROOT']."/dashboard/controllers/file2.php"
file1.php:
class ClassA {
public function functionA()
{
//does its thing
}
file2.php:
include("../../TAO_3.1.0-RC3_build/taoDelivery/controller/file1.php");
class ClassB {
public function functionB()
{
//does its thing, and as testing I included a printout of all included files
$included_files = get_included_files();
foreach($included_files as $filename)
{
echo "$filename\n";
}
}
This does not work, the foreach loop that echoes all the included files successfully includes other files that are included, but not this one. The only different is that the other files are much closer in location, such as just one folder away, rather than multiple folders away.
I have tried
include("file1.php");
rather than the longer one that goes folder by folder, but it doesn't work either. I have also tried using require_once and require, but they just stop the rest of the code and the page does not fully load what it should (fatal error, which makes me more convinced that I'm missing something glaring in my syntax). Any help at all would be really really appreciated, thank you!!
Edit:
I have fixed the relative path, using ../../../ rather than the original two. This hasn't fixed the problem, for some reason. Using require() causes a fatal error and the rest of the code does not occur. I am (unfortunately and not ideally) working on a live website, so I will have to find out how to detect errors on this project in order to see what exact error require() brings up. Thank you for the helpful comments
Edit #2:
I found what the issue with including is, since I do not have access to error logs I dumped the error onto the screen using
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/log.txt');
error_reporting(E_ALL);
It resulted in printing out a fatal error:
Fatal error: Class 'tao_actions_CommonModule' not found in /var/www/html/taoplatform/TAO_3.1.0-RC3_build/taoDelivery/controller/file1.php on line 42
In conclusion, it is not the issue of the include function not working, it is a problem with the file I was trying to include, which is an entirely different problem. Thank you all for the help!