ZF-5544: Zend_Config_Writer_Ini does not comply to current manual example


Catchable fatal error: Argument 1 passed to Zend_Config_Writer_Ini::_addBranch() must be an instance of Zend_Config, string given, called in D:\ZendFramework\library\Zend\Config\Writer\Ini.php on line 119 and defined in D:\ZendFramework\library\Zend\Config\Writer\Ini.php on line 138.

This error is triggered when using Zend_Config_Writer_Ini following the third example in the manual

$writer->write( 'example.ini', $config);

Where $config is a Zend_Config.

This happens because the code expects a section and doesn't account for no sections at all. In fact, the config should have at least one section for the writer to function properly.

However, this example in the manual: "Example 7.1. Using Zend_Config Per Se" shows us that it is possible to have configuration values that are not part of a section.

It is also possible to read config.ini files that contain no sections at all using Zend_Config_Ini.

I think the behavior of Zend_Config_Writer_Ini should be the inverse of Zend_Config_Ini in that what you can legally read with the latter can be legally written with the first.

I will write a test with a Zend_Config object as in Example 7.1 and see if Zend_Config_Ini_Writer will write it properly. If it doesn't it should be fixed.


I attached a patch, that solves this issue and does not break the test.

I do yet have to add a test to avoid regression and I would appreciate if the community would test my patch to see if it still writes other configurations correctly.

Changed Issue type to Patch.

Fixed with r14175 and merged into 1.7 release branch with r14176.