We have a legacy application which doesn't use any of our nice modern frameworks. One problem we're trying to deal with is pollution of the global namespace. As a contrived example, the entry point for the app is file1.php; it requires files, those files require other files...and many of them create variables:
file1.php
$color = 'purple';
require('file2.php');
require('file3.php');
file2.php
$sound = 'waterfall';
require('file4.php');
Eventually, after a few dozen of these files which make up this custom "framework", we get to our actual page.php
where we can write our page-specific code for page.html
. Problem is, $color
and $sound
were created way back in file1 and file2, so now we have to be extremely careful not to accidentally use these variables in our page-specific code.
Any ideas? Would maybe unset
ing all of these variables immediately before page.php
(in the primary "router" I guess) work?