Issue

ZF-10148: Zend_Config_Ini does not properly nest array properties

Issue Type: Bug Created: 2010-07-13T11:39:37.000+0000 Last Updated: 2011-07-27T09:00:23.000+0000 Status: Resolved Fix version(s): Reporter: Scott Rankin (srankin@crsinc.com) Assignee: Rob Allen (rob) Tags: - Zend_Config

Related issues: - ZF-11612

Attachments:

Description

Zend_Config_Ini does not properly nest when array properties are present. When given a config file like this:

property.one.value = foo property.two.value = bar property.array.value[] = foo property.array.value[] = bar

I can do this:

echo $cfg->property->one->value; // prints foo

I would expect to be able to do the following:

$array = $cfg->property->array->value->toArray(); // returns a 2-element array with "foo" and "bar"

but that fails. Inspecting the data of the Zend_Config_Ini object, the key for the array entries is "property.array.value", not "property" with subkey "array" and sub-subkey "value".

Comments

Posted by Rob Allen (rob) on 2010-07-15T13:00:45.000+0000

For an ini file like this:

<pre class="highlight">
[production]
property.one.value = foo
property.two.value = bar
property.array.value[] = foo
property.array.value[] = bar

Loaded like this:

<pre class="highlight">
$config = new Zend_Config_Ini($filename, 'production');
Zend_Debug::dump($config->property->array->value->toArray());

I get this:

<pre class="highlight">
array(2) {
  [0] => string(3) "foo"
  [1] => string(3) "bar"
}

However, something goes wrong if you don't have a section defined.

Posted by Rob Allen (rob) on 2010-07-15T13:29:11.000+0000

I don't think this is fixable.

For an ini file of"

<pre class="highlight">
property.one.value = foo
property.two.value = bar
property.array.value[] = foo
property.array.value[] = bar

[test.value]
a = b
c = d

parse_ini_file() will give this array:

<pre class="highlight">
array(4) {
  ["property.one.value"] => string(3) "foo"
  ["property.two.value"] => string(3) "bar"
  ["property.array.value"] => array(2) {
    [0] => string(3) "foo"
    [1] => string(3) "bar"
  }
  ["test.value"] => array(2) {
    ["a"] => string(1) "b"
    ["c"] => string(1) "d"
  }
}

There's no way to determine the difference between "property.array.value" which is a key and "test.value" which is a section heading. Therefore we assume that they are both section headings which is why you get the behaviour you do.

Posted by Rob Allen (rob) on 2010-07-16T01:28:40.000+0000

Another way to do this is for your ini file to look like this:

<pre class="highlight">
property.one.value = foo
property.two.value = bar
property.array.value.0 = foo
property.array.value.1 = bar

Posted by Rob Allen (rob) on 2010-07-16T01:29:54.000+0000

Resolved as "Won't Fix" as it is not possible to fix it whilst we depend on parse_ini_file()

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-07-16T17:17:37.000+0000

Let me note once more that for ZF2 we should evaluate if we still want to be dependent on parse_ini_file() since we've run across quite a lot of limitations in this seemingly simple function.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2020 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts