Zend Config Ini - Unable to parse array

I can not get the value of the array in the ini file.

Here's the ini file:

module.name = Core module.version = 1 module.package = 'Core Modules' module.dependency[] = Dep1 module.dependency[] = Dep2 module.dependency[] = Dep3 

Here is the code that I use to analyze it:

 $ini = new Zend_Config_Ini('/path/to/module.ini'); 

The following works great:

 echo $ini->module->name; 

This, however, raises an error ("Calling the toArray () member function for a non-object"):

 $ini->module->dependency->toArray(); 

In addition, this returns null:

 var_dump($ini->module->dependency); 

If I changed the ini file to:

 module.name = Core module.version = 1 module.package = 'Core Modules' dependency[] = Dep1 dependency[] = Dep2 dependency[] = Dep3 

I can access the array with:

 $ini->dependency->toArray(); 

I need a module. however, as other configuration files will be in the file.

Any help is much appreciated!

+4
source share
1 answer

You must specify a section at the top of the configuration. Something like that:

 [production] module.dependency[] = Dep1 module.dependency[] = Dep2 module.dependency[] = Dep3 

Now it will be ok:

 $ini = new Zend_Config_Ini('/path/to/module.ini', 'production'); $ini->module->dependency->toArray(); 
+5
source

Source: https://habr.com/ru/post/1381346/


All Articles