无法使用类中定义的变量


unable to use variables defined in class

嗨,我正试图从我创建的配置文件导入配置变量

config。 ,

class Config
{
    public $SERVERNAME = '*******';
    public $SUSERNAME = '*********';
    public $SPASSWORD = '*********';
    public $DBNAME2 = '********';
}

在另一个文件中导入这个变量

include('./Config.php') or die("error");
$cnfig = new Config();

但是当我尝试使用$cnfig->DBNAME2时,它不起作用

请帮忙解决这个问题。

谢谢。

编辑

它在本地系统中工作,当我通过web托管绑定上传时,它不工作。

include  ('./Config.php');
$cnfig = new Config();
echo "<pre>";print_r($cnfig);
编辑:

我得到低于输出,所以它应该也为你工作。

Config Object
(
    [SERVERNAME] => *******
    [SUSERNAME] => *********
    [SPASSWORD] => *********
    [DBNAME2] => ********
)

编辑:2

你也可以这样做

(include('./Config.php')) or die("error");
$cnfig = new Config();
echo "<pre>";print_r($cnfig);

http://www.php.net/manual/en/function.include.php # 39043

or的优先级高于include()

错误输出:

当只使用include('./Config.php') or die("error");时,给出如下错误。


警告:include(1) [function。在D:'path_to_file'myConfig.php第2行中没有这样的文件或目录

警告:include() [function.]include]:在D:'path_to_file'myConfig.php的第2行中打开'1'包含失败(include_path='.;D:'ZendServer'share'ZendFramework'library')

致命错误:在第6行D:'path_to_file'myConfig.php中找不到Class 'Config'