有没有办法在代码中的任何地方使用全局变量?
我想在我将在我的代码中声明的每个路径中使用一个路径变量来定位配置的文件夹。
这是我的代码:Index.php
<?php
require_once('Common.php');
require_once('Path.php');
?>
通用.php
<?php
$RootPath = '.';//in this case its root
//add the RootPath for global using
$GLOBALS['RootPath'] = $RootPath;
?>
路径.php
<?php
class Path {
public static $TemplatePath = $GLOBALS['RootPath'].'/Template.php';
}
?>
这不起作用,因为当我在声明静态变量时尝试调用 $GLOBALS 时,它会显示“解析错误:语法错误,意外的 T_VARIABLE”。
有没有办法做到这一点?
感谢期待亚历克斯