Update: Sara has pointed out a flaw in my last case. The file 'loadFileWithGlobals.php' was incorrectly loading the wrong file -- it should be loading 'withGlobals2.php' (updated now). When it does, access to 'baz2' works as it should.
As I note to in my comment, however, I stand by my original rant: relying on globals for your applications is a bad practice, as it makes them difficult to integrate with other applications later. Developers using your application should not need to hunt down exactly when a global is first declared and explicitly push it into the global scope in order to get that application to integrate with others. Use other means, such as singletons or registries, to persist configuration within your applications.
In my last entry,
I evidently greatly simplified the issue to the point that my example
actually didn't display the behaviour I had observed. I'm going to show a
more detailed example that shows exactly the behaviour that was causing
issues for me.
First off, this has specifically to do with including files from within
functions or class methods that then call on other files that define values
in the global scope. In the original example, I show an action controller
method that includes the serendipity bootstrap file, which in turn loads a
configuration file that sets a multi-dimensional array variable in the
global scope. Without first defining the variable in the global scope, this
method of running serendipity fails.
Now, for the examples.