为站点创建配置系统时遇到(警告:字符串偏移量非法)


Encountered (Warning: Illegal string offset) while creating a configuration sytem for a site

我喜欢这种配置,因为它更干净,所以我有一个包含以下内容的配置文件:

<?php
 $Config['option_1'] = 'some value';
 $Config['option_2'] = 'some value';
 $Config['option_3'] = 'some value';
?>

然后我有一个类,其中包含加载此类配置文件的方法 它与CodeIgniter加载配置文件的方式非常相似,除非我包含此文件,我得到:

Warning: Illegal string offset 'option_1' in 'Path to the config file' on line #.
Warning: Illegal string offset 'option_2' in 'Path to the config file' on line #.
Warning: Illegal string offset 'option_3' in 'Path to the config file' on line #.

等。你明白了。

我已经到处搜索了如何在站点上使用这种配置系统,但没有结果。因此,如果有人有指向教程或一些文档的链接,那么请帮助我了解它是如何工作的,或者当我使用其中一种方法需要类内部的配置文件时,为什么会出现该错误。

注意。当我将配置文件直接加载到浏览器中时,我没有收到任何错误,并且我可以使用"echo $Config['option_1'];"成功地回显出任何值

如果你这样做

var_dump($Config);

您会发现它不像您想象的那样是一个数组。