我正在寻找一种将范围设置require_once()
为全局范围的方法,当require_once()
在函数内部使用时。类似以下代码的东西应该可以工作:
文件“foo.php”:
<?php
$foo = 42;
实际代码:
<?php
function includeFooFile() {
require_once("foo.php"); // scope of "foo.php" will be the function scope
}
$foo = 23;
includeFooFile();
echo($foo."\n"); // will print 23, but I want it to print 42.
有没有办法明确设置范围require_once()
?有没有很好的解决方法?