4

I cannot get the value of an array in an 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's the code I use to parse it:

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

The following works fine:

echo $ini->module->name;

This, however, causes an error ('Call to a member function toArray() on a non-object'):

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

Also, this returns null:

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

If I change 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 by using:

$ini->dependency->toArray();

I want the 'module.' prefix, however, because other config data will be in the file.

Any help is greatly appreciated!

1 Answer 1

5

You should specify a section in the top of the config. Something like this:

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

Now this will do ok:

$ini = new Zend_Config_Ini('/path/to/module.ini', 'production');
$ini->module->dependency->toArray();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.