I have spent a couple hours wasting my time on this now and I am just completely stumped. I sure hope someone can explain this one. Even the freenode/#php guys have exhausted their efforts on this one...
I am developing a web application, the nature of which is irrelevant. The basic structure is as follows:
The application has a dozen or so documents. As an example, let's use comments.php.
Each of these documents starts off with a require_once() call which requires the include/init.php initialization script. The init.php file defines some site-wide variables, starts an http session and includes a few more libraries. In particular, init.php has 3 require_once() calls for the the following files:
/usr/lib/php/adodb/adodb.inc.php
include/codegallery.inc.php
include/functions.php
After including these files and setting variables, init.php finishes up and hands control back to the calling script (in this example, comments.php). So far, so good.
I promise I'm getting to the point, I just want to give all the information I can think of which might help you help me. 😉
So, now that the initalization routines are complete, the primary script then does its thing. It does any processing requires depending on arguments which were passed to the script and then it generates an html page. Of important note, two files are included as part of the html layout. header.php and footer.php. After header.php, the page content is printed, followed by the inclusion of footer.php and it's all over.
Here's where it gets really bizarre.
The file called codegallery.inc.php is my own library which defines four classes, the names of which are of no relevance. The problem I am having is that these classes are available throughout the entire processing of the script except in header.php's part. I have done a lot of testing by echoing the class_exists() result for the classes and basically they work everywhere except inside header.php. When I make a reference to the classes from within that file, it gives a fatal error saying they are undefined.
Note that in the primary script (after header.php's inclusion) the classes ARE still defined and accessible. So as soon as codegallery.inc.php gets included, everything is great. Right up until header.php inclusion, everything is still great. And AFTER header.php, still great. I just cannot see them inside that file.
Does anyone have any clue whatsoever as to why I cannot access the classes inside that one file? Is there some limit to the depth of file inclusion which I am reaching which prevents files from access values set in files too many levels up?
Basically this is the hierarchy of the included files as the script goes:
- comments.php
|
+-+ init.php
| +--+ codegallery.inc.php
| |
| +--+ functions.php
|
+--+ adodb.inc.php
|
+--+ header.php
|
- + footer.php