Since your original question has already been answered let me suggest another approach that avoids global variables all together.
You seemingly have a function + a default value that you set as a global variable. You can also define default values for function parameters.
<?php // test.php
function test($flags=4) {
echo '<br/>in test flag="'.$flags.'"';
if ($flags!=0) {
echo ' flag works';
}
}
No global variable, but you can still call test() without a parameter and the function will use the default value - which you can overwrite by passing the parameter.
function something() {
$include_file = 'test.php';
if ( file_exists($include_file) ) {
require_once ($include_file);
echo "\nwithout parameter: "; test();
echo "\nwith a parameter: "; test(16);
}
}
something();
exit;
prints
without parameter: <br/>in test flag="4" flag works
with a parameter: <br/>in test flag="16" flag works
That's not exactly the same behavior but it may be what you wanted in the first place....
edit: Another point could be the
if ( file_exists($include_file) ) {
require_once ($include_file);
construct you're using. I don't have a strong opinion (or any strong evidence ;-)) on that but you might want to consider using
$something = include $include_file;
if ( false!==$something ) { /* error handling here... */ }
instead. include "returns" false if php can't include the file. All that's required for this to work is that the included file doesn't explicitly return FALSE. This might be cache friendlier (e.g. when using something like APC). But again: I have no proof for this at hand, just a hunch. At least it gives your code a chance to handle an error "gracefully".