【发布时间】:2026-01-28 14:30:01
【问题描述】:
所以我有这个问题,我有 3 个类似的文件
2.php
<?php
$variable = 4;
?>
1.php
<?php
class foo {
function bar() {include_once('2.php');}
}
?>
index.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;
?>
它会起作用,有什么解释吗? 谢谢
【问题讨论】: