I think that you probably have a logical error somewhere where the contents of the variables get destroyed, or as @Kev noted, the execution thread is wrong. Here are some test codes:
File: test.php
<?php $test = "Hi!"; require_once 'test2.php'; require_once 'test3.php'; ?>
File: test2.php
<?php echo("Test 2: " . $test . "<br/>"); ?>
File: test3.php
<?php echo("Test 3: " . $test . "<br/>"); ?>
This leads to the output:
Test 2: Hi! Test 3: Hi!
Which proves that the variable $test in the global scope, and should be available for any script after it is defined.
PS - Don't rely on SO users to provide your reference material. Go straight to the source: Scope Variable - PHP Manual The first paragraph on this page reads:
The scope of a variable is the context within which it is defined. For most PHP variables, they only have a single scope. This is the only area included and required files, as well.
Edit
Try this in header.php and see what happens:
<?php include 'navigation.php'; echo($previous . " ; " . $next . "<br/>"); include 'backnext.php'; echo($previous . " ; " . $next . "<br/>"); ?>
If you do not get the same result both times, then there is a problem in backnext.php where the variables get wiped. If it produces the same output, then move the echoes inside backnext.php at the highest and lowest level. Logically, they donโt actually move them, but you can move them closer and closer until you find where the problem is.
source share