Home » Configuration » Config » Bug #3590
Error when using config to load a php array
Details
| Submitted | 2005-02-25 09:54 UTC |
|---|---|
| From | arthur at movenext dot nl |
| Assigned | aashley |
| Status | Closed |
| Package | Config |
| PHP Version | 4.3.10 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-02-25 09:54 UTC] arthur at movenext dot nl
Description:
------------
I get the following error:
Warning: Invalid argument supplied for foreach() in /usr/share/php/Config/Container/PHPArray.php on line 99
The functions works fine otherwise. The problem only occurs in version 1.10.4. If I use version 1.10.3 I do not have this problem
[2005-02-25 17:38 UTC] ryansking at mac dot com
Can you give us some more info? Like a piece of code
that reproduces the error (and I literally mean a piece
of code that causes the error).
[2005-02-28 13:26 UTC] arthur at movenext dot nl
The code I use is:
require_once('Config.php');
$c = new Config();
$root =& $c->parseConfig($c_path.$this->modPath.'settings.inc', 'PHPArray', array('name' => '_SETTING'));
where $c_path.$this->modPath.'settings.inc' is a settings file with a php array in it.
[2005-04-02 00:17 UTC] ryansking at mac dot com
Sorry for ignoring this bug for so long...
When I asked for code to reproduce the bug, I really
need the config file (or something like it that causes
theh same error).
[2005-04-08 23:07 UTC] matte at silent-e dot com
the problem code was introduced in PHPArray.php CVS version 1.23. Fixing bug #3298 introduced the error.
config array to test...
$conf['mysql'] = array(
'user' => 'croooow',
'password' => 'coolrobot',
'host' => 'localhost',
'database' => 'deep13'
);
$conf['emergencyemails'] = array(
'joel@example.org',
'cambot@example.org'
);
the "emergencyemails? array will cause the problems due to the keys being integers. PHPArray.php v1.22 in CVS should not have a problem with this
[2005-05-13 15:20 UTC] nkahn at cmd dot lu
I have patched PHPArray.php as describe above. I don't know if it's necessary to handle differently array using interger key and array using string key. The fact is that the way it's actually handled is wrong since you are trying to parse a variable that is no more an array ($nestedValue) since you extracted it using a foreach statement.
if (is_array($value)) {
/*
if (is_integer(key($value))) {
foreach ($value as $nestedValue) {
$section =& $container->createSection($key);
$this->_parseArray($nestedValue, $section);
}
} else {
$section =& $container->createSection($key);
$this->_parseArray($value, $section);
}
*/
$section =& $container->createSection($key);
$this->_parseArray($value, $section);
} else {
$container->createDirective($key, $value);
}
Here is my configuration file.
$db_data['configtypes'][0] = 'All';
$db_data['configtypes'][1] = 'WAP - CSD';
$db_data['configtypes'][2] = 'WAP - GPRS';
$db_data['configtypes'][3] = 'MMS - GPRS';
$db_data['configtypes'][4] = 'WEB - GPRS';
Could you have a look at it ?
Thanks.
[2005-10-24 14:22 UTC] bugs dot pear at gage dot fr
I've personnaly patched the code this way :
if (is_array($value)) {
if (is_integer(key($value))) {
foreach ($value as $nestedValue) {
if(is_array($nestedValue)) {
$section =& $container->createSection($key);
$this->_parseArray($nestedValue, $section);
}
else {
$container->createDirective($key, $nestedValue);
}
}
} else {
$section =& $container->createSection($key);
$this->_parseArray($value, $section);
}
} else {
$container->createDirective($key, $value);
}
What do think of this ?
[2005-12-20 00:03 UTC] aashley at php dot net
confirmed bugs dot pear at gage dot fr's patch works. available as patch at:
http://www.adamashley.name/stuff/config-bug-3590.patch
[2005-12-24 02:30 UTC] aashley at php dot net
This bug has been fixed in CVS.
If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).
If this was a problem with the pear.php.net website, the change should be live shortly.
Otherwise, the fix will appear in the package's next release.
Thank you for the report and for helping us make PEAR better.