所以我有这个问题我有3个文件,比如
2.php
<?php
$variable = 4;
?>
1.php
<?php
class foo {
function bar() {include_once('2.php');}
}
?>
索引.php
<?php
include_once('1.php');
$foo = new foo;
foo->bar();
echo $variable;
?>
为什么它告诉我变量没有价值?如果我喜欢这样
<?php
include_once('1.php');
$foo = new foo;
foo->bar();
include_once('2.php');
echo $variable;
?>
它也行不通。只有这样
<?php
include_once('1.php');
$foo = new foo;
//foo->bar();
include_once('2.php');
echo $variable;
?>
它会起作用,有什么解释吗?谢谢