Issues

ZF-2843: Warning: array_merge_recursive(): recursion detected in Zend\Config\Ini.php on line 134

Description

While trying to figure out how Zend_Config_Ini deals with invalid ini-files, I stumbled upon this error message: {quote} Warning: array_merge_recursive() [function.array-merge-recursive]: recursion detected in [...]Zend\Config\Ini.php on line 134 {quote}

I can't figure out why this happens, but I can reproduce it.

Notice that there are no sections in the config file.

config.ini:


abc = def

ghi = jkl

index.php:


require_once('Zend/Loader.php');

Zend_Loader::loadClass('Zend_Config_Ini');
try
{
    $myIniConfig = new Zend_Config_Ini('./config.ini', null, array('nestSeparator' => '.'));
}
catch (Exception $e)
{
    echo "Could not load configuration - {$e->getMessage()}";
    exit;
}

Replacing line 134


$dataArray = array_merge_recursive($dataArray, $this->_processKey($config, $sectionName, $sectionData));

with the following code


$tmp = $this->_processKey($config, $sectionName, $sectionData);
$dataArray = array_merge_recursive($dataArray, $tmp);

seems to take care of it for whatever reason, but I still can't tell exactly why it happens so I'm not sure how to properly fix it.

Maybe this is a problem with PHP function array_merge_recursive() - I don't know.

A somewhat related issue, perhaps better suited for a mailing list than here, but I'm lazy.. While trying to debug this issue, I found it a little hard to figure out the meaning of a lot of code in Zend\Config\Ini.php.. For example, why is the $config variable being used as a parameter for a call to $this->_processKey() on that line (134)? That variable holds settings that may be passed to Zend_Config_Ini to configure allowModifications and nestSeparator, so why did it suddenly change its purpose? Or is it really supposed to do that? The result is that you can use $myIniConfig->nestSeparator or $myIniConfig->allowModifications (using $myIniConfig from my reproduction code above) to get those internal settings the same way you would get settings from the parsed ini file, I assume that this is not the intented behaviour.. (shouldn't only settings from the ini file be available as object members like that)?

I see that method _processKey() uses its own variable named $config, maybe that's what caused the confusion (assuming I'm not the one who's confused, but that may very well be a wrong assumption ;-))?

I guess that somewhere between the lines here I'm saying that it could be helpful with more code comments where it's not immediately obvious what's happening, just in case someone else are going to maintain the package sometime in the distant future.. I for one feel that I've spent far too much time on nothing trying to debug this thing, but it might have been a lot easier if it were easier to read what was going on.

Comments

Hi,

You are right. I've fixed the actual bug by renaming the constructor parameter to $options.

This is committed to trunk in svn r8741.

I will open a separate issue to refactor Zend_Config_Ini to make it more understandable.

Regards,

Rob...

Fixed. I've opened http://framework.zend.com/issues/browse/ZF-2849 for improving the internals of Zend_Config_Ini.

Darby,

Do you want me to apply to branch/release-1.5/ ?

Yes, but please wait until after code freeze has been announced as lifted. Thanks! :)

I'm assuming this fix is merged to the 1.5 release branch for release with 1.5.1. Please update JIRA if this is not the case.

It is now!

Sorry - I had it ready to go locally, but forgot to commit after 1.5.0 was released.

Rob...