how to use function to require php file not changing global vars environment?
if using function ,and in function codes "require(xxx.php)",then all the vars in xxx.php are not global vars again. for the example bellow , I want to get the result is "linjuming", but the oop.php is required in the require_part() function ,so echo $name is not 'linjuming' any more.
pls dont use global $name in require_part function . for this function is a common function to require any php file. other php files have their own global vars.
my codes here:
<?php
$name='linjuming';
class my_template{
function require_part($part_name){
if(file_exists($part_name.'php')){
require($part_name.'php');
}
}
}
$tmp=new my_template();
$tmp->require_part('oop');
/*
oop.php codes:
<?php echo $name; ?>
I want to run component php file and do not change the global environment;
how to do that?
*/
?>