在这种情况下取​​消设置PHP变量是不错的做法?

Right now, I am using a modified version of OsCommerce that has a lot of variables declared in its application_top.php file (which is included when going to every file on the website as the first thing).

So for instance, if I go to mypage.php, application_top.php is included in the top.

I only want some of the variables defined from my application_top.php file to be accessible inside the mypage.php file, since they are used for temporary calculations or whatever, whereas others are meant to be accessible from the page.

What would be the best practise? To unset variables that are meant to be used in the local scope after use, and to leave all variables that are meant to be accessed alone?

use of classes would be the best way, and just passing the variables you need

Though I assume this will be a major rewrite ?

What about something like this

$vars = array_keys(get_defined_vars());
$whitelist = array("var1", "var2" ...);
$vars = array_diff(array_keys($whitelist), $vars);
foreach($vars as $var) {
    unset($$var); 
}