There are 3 .php files:
vars.php
$foo = 'bar';
header.php:
include_once("vars.php");
echo "In header: $foo";
footer.php:
include_once("vars.php");
echo "In footer: $foo";
In the above situation, $foo is not set in footer.php. If I remove the include_once() in header.php, then $foo is set in footer.php, but not header.php.
I’m guessing I’m making a silly somewhere, but for the life of me I can’t find it.
The
..._once()functions don’t care WHERE the include/require occured. Once a file has been included, it’ll never been include_once/require_once again anywhere during that particular script execution run.If you need to include it multiple times in different locations, then don’t use the _once() variants.