Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.12

Bug #10010 numeric index lost when parsing subarrays
Submitted: 2007-02-02 11:33 UTC
From: werner at seagullproject dot org Assigned: aashley
Status: Closed Package: Config (version 1.10.9)
PHP Version: 5.1.2 OS: linux
Roadmaps: 1.10.10    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2007-03-23 01:28 UTC
Package:
Bug Type:
Summary:
From: werner at seagullproject dot org
New email:
PHP Version: Package Version: OS:

 

 [2007-02-02 11:33 UTC] werner at seagullproject dot org (Werner Krauss)
Description: ------------ we have an array with subarrays (e.g. list of month names) that should be saved as a phparray file. the numeric indexes of the month names get lost when parsing the array, instead the array begins with index 0. Maybe the changes from http://pear.php.net/bugs/bug.php?id=3590 caused this behaviour? Commenting out the "is_numeric" clause gives me the expected result. Test script: --------------- $aTrans = array( 'foo' => 'bar', 'aMonths' => array( 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December',) ); $c = new Config(); $root = & $c->parseConfig($aTrans, 'phparray'); $filename = './test.php'; $result = $c->writeConfig($filename, 'phparray', array('name' => 'words')); include($filename); print_r($words) Expected result: ---------------- save file like $words['aMonths'][1] = 'January'; $words['aMonths'][2] = 'February'; Actual result: -------------- file is saved like: $words['aMonths'][0] = 'January'; $words['aMonths'][1] = 'February';

Comments

 [2007-02-06 08:09 UTC] aharvey (Adam Harvey)
Well, we can either re-break bug #3298 and fix this issue, or leave this broken and leave #3298 "fixed". I'm not sure we can have both bugs fixed, given the limitations of Config internally. Bumping to aashley for a final decision on this.
 [2007-03-23 01:28 UTC] aashley (Adam Ashley)
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. AH is quite correct it's not possible to correct both cases and I can see legitimate claims to both behaviours. So I've added a configuration option to the PHPArray container that allows you to switch off the current behaviour. The current behaviour treats an integer array as a generated array indicated multiple directives of the name of it's parent. Note it does not treat numeric strings in this way so if your example was: array( '1' => 'January', '2' => 'Feburary', ); it would work as you expected. This behaviour is to support converting to and from other containers that support duplicated directives (ie XML, Apache). I have added the option 'duplicateDirectives' to the PHPArray Container setting this to false will cause it to treat integer indexes as strings and create them each as an individual directive.