ZF-11116: A bug report with a correction.



I met a bug on Zend Framework 1.11.3 while using Zend_Config_Writer_Array::write().

This method generates a PHP file containing an array() with all data from an ini file, here is the code from my "public/index.php" :

$config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/application.ini"); $writer = new Zend_Config_Writer_Array(array("config" => $config, "filename" => $cache_filename)); $writer->write();

In fact, my idea is to create a compiled PHP structure to prevent parsing the "application.ini" file at each execution, next to this I created the Zend_Application with this parameters :

$application = new Zend_Application( APPLICATION_ENV, $cache_filename );

With this code, I have an exception on the default controllers directory wich was not defined.

This is caused by an issue on the Zend_Application class at line 404, the 'php'/'inc' case return the config structure without taking account of the $environment variable (contrary to the other cases, indirectly by $config->toArray() at line 410), this gives an array incompatible with the rest of the process.

So the only fix I made on my side was at line 404 :

return $config[$environment];

All seems to be ok on my version since this modification.

Best regards, Cédric Tailly


Your fix makes the assumption that the configuration file is subdivided internally by the possible values of APPLICATION_ENV, which is not always the case. If you are using the php/inc suffix on your configuration files then Zend_Application assumes you will create a separate file for each value of APPLICATION_ENV and pass in the proper filename at runtime.

That said, making this change would likely break backwards-compatibility for existing applications, so I would suggest bringing this issue up with the maintainer of Zend_Application (or it's successor) in ZF 2.0 to see if it can be addressed there.

Ability to cache parsed configuration files has been added to ZF2