PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Configuration » Config » Bug #8357

Unexpected result from IniFile when comma in use

Details

Submitted2006-08-04 09:14 UTC
Fromteon dot ooi at gmail dot com
Assignedaashley
StatusClosed
PackageConfig
PHP Version5.0.4
OSWindows
Roadmaps(Not assigned)

Comments

[2006-08-04 09:14 UTC] teon dot ooi at gmail dot com

Description:
------------
When I try to use comma(,) inside the ini with double quote("), the value will split into arrays which I don't want to.

config.ini:

[meta]
robots = "index, follow"
keywords = "key, words"

In Config/Container/IniFile.php, line 71:
...
foreach ($value as $directive => $content) {
if (strpos($content, '"') === false) {
$values = preg_split('/\s*,\s+/', $content);
...

The strpos() does not return the position of first occurrence of double quote(") since it has been removed from the parse_ini_file() when parse the file.

Test script:
---------------
<?php
require_once('Config.php');
$config = new Config;
$root =& $config->parseConfig('config.ini', 'IniFile');
$settings= $root->toArray();
var_dump($settings);
?>

Expected result:
----------------
array(1) {
["root"]=>
array(1) {
["meta"]=>
array(2) {
["robots"]=>
array(2) {
[0]=>
string(5) "index"
[1]=>
string(6) "follow"
}
["keywords"]=>
array(2) {
[0]=>
string(3) "key"
[1]=>
string(5) "words"
}
}
}
}

Actual result:
--------------
array(1) {
["root"]=>
array(1) {
["meta"]=>
array(2) {
["robots"]=>
string(12) "index, follow"
["keywords"]=>
string(9) "key, words"
}
}
}

[2006-08-11 01:49 UTC] aashley at php dot net

I don't think I can fix this behaviour without completely removing the ability to split options on commas. As that behaviour is expected I don't think removing it is an option at this point.

I'd suggest you switch to using the IniCommented Container which parses your sample ini file in as expected.