Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.12

Bug #378 INI files should not have root [] when writing config
Submitted: 2003-12-08 14:43 UTC
From: jstump Assigned: mansion
Status: Closed Package: Config
PHP Version: 4.3.3 OS: Debian GNU/Linux x86
Roadmaps: (Not assigned)    
Subscription  


 [2003-12-08 14:43 UTC] jstump
Description: ------------ When I create an INI file I have to define a "root" section, which results in the following: [database] [test] foo=bar asdf=asdf bar=foo [test__keys] foo=1 bar=1 asdf=asdfasdf lkjh=asdf or just simply [] [test] foo=bar asdf=asdf bar=foo [test__keys] foo=1 bar=1 asdf=asdfasdf lkjh=asdf Reproduce code: --------------- $root = & new Config_Container('section','database'); while(list($key,$val) = each($initial['root'])) { $sect = & $root->createSection($key); if(is_array($val) && count($val)) { while(list($item,$data) = each($val)) { $sect->createItem('directive',$item,$data); } } } print_r($initial); $config->setRoot($root); $config->writeConfig(); Expected result: ---------------- I don't think, when writing INI files, that you should have the "root" written. I'm not sure of a good way to do this though. I see two ways: 1.) if all of root's children are sections and root containers no data (ie. directives, etc.) then don't write it out in INI files -or- 2.) create some sort of blank container so that I can create "rootless" lists of sections.

Comments

 [2004-06-04 09:12 UTC] bmansion at mamasam dot com
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. 1. (NOT RECOMMENDED) You can do what you want like this: $config->container =& $root; But I agree that it is not very secure as container is supposed to be private or will be in a PHP5 version as we need to ensure that it is a Config_Container object before accepting it to replace the root container. 2. I have changed the setRoot() code in Config.php to accept a root container, to actually replace the current root container instead of adding the given container as a child to an automatically generated root container. This will work only if the given container name is 'root' and its type is 'section'. So in your case, instead of : $root = & new Config_Container('section','database'); $config->setRoot($root); You will need to have : $root = & new Config_Container('section','root'); $config->setRoot($root);