I'm having a strange problem with requires that I've searched over multiple discussion boards and haven't seen anything that addresses it. The problem. in short, is that I have 4 scripts in the following directories:
- /SendEmail.php
- /common/constants/DatabaseConstants.php
- /common/lib/DatabaseLibrary.php
- /common/lib/EmailLibrary.php
All of the files are rooted off the web server document root. The SendEmail.php file has a require_once() including the EmailLibrary file and calling the sendEmail() function in that library. The sendEmail() function require_once()'s the DatabaseConstants and DatabaseLibrary files and calls the constructInsert() function on DatabaseLibrary. Inside that function it again require_once()'s the DatabaseConstants file.
In this scenario, I have a problem where constants defined in the DatabaseConstants file are not recognized in EmailLibrary or DatabaseLibrary functions if I use require_once(). If I switch to using require() the functions read in the file but, in this case, I get an error because the same file is included twice.
I'm trying to make this code highly modular and not rely on certain constants being included in calling code (i.e. rely on constants being included in the code that calls the constructInsert() function. The way I understand the way that these functions should work is that if you require the same code more than once in one call chain that require_once() avoids include conflicts, but I'm getting this kind of strange erratic behavior when requiring files in functions that call other functions.
Any ideas? I'm very stumped.