Page 1 of 1

file includes - stopping multiple calls to same function

Posted: Wed Aug 13, 2003 5:09 pm
by Tachyon
Hello, everyone.
I'm having trouble understanding some code to guard against accidentally calling on a function more than once when using included files.

"declare a variable in every include file you create:
$COMMON_INCLUDED=1;

and then test for it at the beginning of the include:
if (!$COMMON_INCLUDED) $COMMON_INCLUDED=1;
"

I don't understand this very well. Could someone please explain this to me? Does this mean that each file you include should have $COMMON_INCLUDED=1; in it? I don't understand what the 2nd line of code does or what it means.

Any help would be greatly appreciated.

Posted: Wed Aug 13, 2003 6:36 pm
by qartis

Code: Select all

if (!$COMMON_INCLUDED) $COMMON_INCLUDED=1;
If I were to say that code out loud, it would come out:
If NOT $common_included, set $common_included to '1'.
And in php, !$var is the same as 'empty($var)' : If there is NO value for $var, then the code after the IF will be executed.

If your code is to check to see what files are included, then this snippet might help:

Code: Select all

foreach (get_included_files() as $filename){
echo $filename."<br />\r\n";
}
This code will print out a listing of every file that has been included (or required)