在创建站点的配置系统时遇到(警告:非法字符串偏移量) [英] Encountered (Warning: Illegal string offset) while creating a configuration sytem for a site
问题描述
我喜欢这种配置,因为它更干净,因此我有一个配置文件与以下:
I like this kind of configuration because it's more cleaner therefore I have a configuration file with the following:
<?php
$Config['option_1'] = 'some value';
$Config['option_2'] = 'some value';
$Config['option_3'] = 'some value';
?>
然后我有一个类有一个方法来加载这种配置文件它与CodeIgniter加载配置文件,除非我包括这个文件我得到:
Then i have a class with a method to load this kind of configuration files It's very similar with how CodeIgniter loads the configuration files except when i include this file I get:
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 #.
等。
我已经搜索了如何在网站上使用这种配置系统,但没有结果。所以如果任何人有一个教程或一些文档的链接,那么请帮助我了解这是如何工作,为什么我得到这个错误,当我需要一个类中使用它的方法之一的配置文件。
I've searched everywhere on how to use this kind of configuration system on a site but no result. So if anyone has a link to a tutorial or some documentation on this then please help me understand how this works or why i get that error when I require the configuration file from inside a class using one of it's methods.
注意。当我将配置文件直接加载到浏览器中时,我没有得到任何错误,我可以使用echo $ Config ['option_1'];
Note. When i load the configuration file directly into the browser I get no errors and I can successfully echo out any values using "echo $Config['option_1'];"
推荐答案
如果你这样做
var_dump($Config);
你会看到它不像你想的数组。
you'll see that it's not an array like you think.
这篇关于在创建站点的配置系统时遇到(警告:非法字符串偏移量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!