Include and Require
Include Once Guard
include_once loads a file only the first time the program asks for it.
Include Once Guard
include_once_guard.php
<?php
$base = ;
$loadCount = 0;
include_once __DIR__ . "/counter_setup.inc";
include_once __DIR__ . "/counter_setup.inc";
$total = $base + $loadCount;
echo "loadCount=" . $loadCount . "\n";
echo "total=" . $total . "\n";
<?php
$base = ;
$loadCount = 0;
include_once __DIR__ . "/counter_setup.inc";
include_once __DIR__ . "/counter_setup.inc";
$total = $base + $loadCount;
echo "loadCount=" . $loadCount . "\n";
echo "total=" . $total . "\n";
<?php
$base = ;
$loadCount = 0;
include_once __DIR__ . "/counter_setup.inc";
include_once __DIR__ . "/counter_setup.inc";
$total = $base + $loadCount;
echo "loadCount=" . $loadCount . "\n";
echo "total=" . $total . "\n";
one-time load
Including a setup file twice with `include_once` avoids running the setup twice.