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.
file includes - stopping multiple calls to same function
Moderator: General Moderators
Code: Select all
if (!$COMMON_INCLUDED) $COMMON_INCLUDED=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 NOT $common_included, set $common_included to '1'.
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";
}