Home » Configuration » Config » Bug #8168
Wrong phparray result when the $new_cfg_ary has numeric keys
Details
| Submitted | 2006-07-09 03:03 UTC |
|---|---|
| From | macroz at gmail dot com |
| Assigned | aashley |
| Status | Wont fix |
| Package | Config |
| PHP Version | 5.1.1 |
| OS | windows |
| Roadmaps | (Not assigned) |
Comments
[2006-07-09 03:03 UTC] macroz at gmail dot com
Description:
------------
Please run the test script!
Test script:
---------------
require_once("Config.php");
$new_cfg = array(
5=>array(54=>'5aaa',52=>'5bbb',56=>'56c',59=>'59c'),
7=>70,
3=>array(31=>'test3.0','test3.1',30=>'test3.2','test3.3')
);
$c = new Config();
$root =& $c->parseConfig($new_cfg, 'phparray');
echo '<pre>';
print_r($new_cfg);
echo '<hr>' . $root->toString('phparray', array('name' => 'new_cfg')) .'</pre>';
exit();
Expected result:
----------------
var_dump($new_cfg):
=================================
Array
(
[5] => Array
(
[54] => 5aaa
[52] => 5bbb
[56] => 56c
[59] => 59c
)
[7] => 70
[3] => Array
(
[31] => test3.0
[32] => test3.1
[30] => test3.2
[33] => test3.3
)
)
Actual result:
--------------
$new_cfg['5'][0] = '5aaa';
$new_cfg['5'][1] = '5bbb';
$new_cfg['5'][2] = '56c';
$new_cfg['5'][3] = '59c';
$new_cfg['7'] = 70;
$new_cfg['3'][0] = 'test3.0';
$new_cfg['3'][1] = 'test3.1';
$new_cfg['3'][2] = 'test3.2';
$new_cfg['3'][3] = 'test3.3';
[2006-08-11 02:22 UTC] aashley at php dot net
I don't believe this can be fixed without breaking required behaviour for converting between Container types.
If you change your keys to strings:
$new_cfg = array(
'5' => array('54' => '5aaa', '52' => '5bbb', '56' => '56c', '59' => '59c'),
'7' => 70,
'3' => array('31' => 'test3.0', 'test3.1', '30' => 'test3.2', 'test3.3')
);
it should behave as expected.
The current behaviour is required for handling conversion to containers that can have multiple sections of the same name. These sections are converted to an integer based array for representation in the PHPArray backend.