PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Configuration » Config » Bug #3561

numeric keys in arrays

Details

Submitted2005-02-23 09:25 UTC
Fromvh at dmc dot de
StatusBogus
PackageConfig
PHP VersionIrrelevant
OSlinux
Roadmaps(Not assigned)

Comments

[2005-02-23 09:25 UTC] vh at dmc dot de

Description:
------------
Hi,

i can't use numeric keys in a config array.
After saving them and then loading it again there is a error in the foreach line in function _parseArray.

it's the problem in the default part of the function checking on is_integer(key).
Why do you do that ?

Regards
Volker

Reproduce code:
---------------
$conf =& new Config_Container('section', 'conf');
$conf_DB =& $conf->createSection('DB');
$conf_DB->createDirective('0', 'mysql');
$conf_DB->createDirective('1', 'localhost');
$conf_DB->createDirective('2', 'root');
$conf_DB->createDirective('3', 'root');

// set this container as our root container child in Config

$config = new Config();
$config->setRoot($conf);

// print the content of our conf section to screen

echo $conf->toString('phparray', array('name' => 'test'));
// print the content of our conf section to screen

$config->writeConfig('/tmp/config_test.php', 'phparray',
array('name' => 'test'));
$conf = new Config;
$root =& $conf->parseConfig('/tmp/config_test.php', 'phparray',array('name'=>'test'));

echo $root->toString('phparray',array('name'=>'test1'));

Expected result:
----------------
Warning: Invalid argument supplied for foreach() in /usr/local/lib/php/Config/Container/PHPArray.php on line 99

[2005-04-02 00:16 UTC] ryansking at mac dot com

Thank you for taking the time to write to us, but this is not
a bug.

Unfortunately, Config can't handle numeric directive
names right now. This is because of the way multiple
directives of the same name are serialized into a php
array.

Also, why use Config this way? Why not name the
directives?