在使用class列文件时,经常会include一些文件,而有时我们需要使用这些变量。
1.php
<?php
$str="aaaaaa";
?>
2.php
<?php
include "1.php";
class Text{
function fun1(){
global $str;
echo $str;
//或echo $GLOBALS['str'];
}
}
?>
<?php
include "2.php";$test = new Text();
$test->fun1();
?>