比如我有3個文件:PHP的問題與變量
首先index.php
與下面的代碼:
<?php
include("includes/vars.php");
include("includes/test.class.php");
$test = new test();
?>
然後vars.php
與下面的代碼:
<?php
$data = "Some Data";
?>
和最後test.class.php
<?php
class test
{
function __construct()
{
echo $data;
}
}
?>
當我運行index.php時,Some Data
的值從$data
變量不顯示,如何讓它工作?
在這種情況下使用全局變量被認爲是不好的做法。 – 2011-06-01 09:19:18
是的。這正是我所說的。 「但是,在班級中使用全局變量是不行的。」 – 2011-06-01 09:20:21
但如果要使用$ GLOBALS [data]?這是好事還是會導致以後出現問題? – John 2011-06-01 09:25:42