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

Bug #7058 array_merge breaks bc in decorator
Submitted: 2006-03-08 10:12 UTC
From: bate Assigned: quipo
Status: Closed Package: Translation2 (version 2.0.0beta9)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2006-03-08 10:12 UTC] bate (Marco Kaiser)
Description: ------------ There was a change in Decorator\Lang.php file line 124 Beta8: $data1 = $this->translation2->getPage($pageID, $langID); $data2 = $this->translation2->getPage($pageID, $this->fallbackLang); foreach ($data1 as $key => $val) { ... Beta9; $data1 = $this->translation2->getPage($pageID, $langID); $data2 = $this->translation2->getPage($pageID, $this->fallbackLang); $data1 = array_merge($data2, $data1); foreach ($data1 as $key => $val) { this results in a loosing array_keys in the result of this call. i dont know why its required to merge the array's here because you overwrite the data1 with the content from data2 array. possible workaround is to remove the line of code or use $data2 + $data1 instead of array_merge. btw. array_merge produces with arraykey of typ int a complete different result as expected i think Test script: --------------- <?php $data1 = array(1100 => 'a', 'b', 'c', 'd'); $data2 = array(1100 => 'a', 'b', 'c', 1500 => 'z'); print_r(array_merge($data2, $data1)); print_r($data2 + $data1); Expected result: ---------------- Array ( [0] => a [1] => b [2] => c [3] => z [4] => a [5] => b [6] => c [7] => d ) Array ( [1100] => a [1101] => b [1102] => c [1500] => z [1103] => d )

Comments

 [2006-03-08 15:03 UTC] quipo
> i dont know why its required to merge the array's > here because you overwrite the data1 with the > content from data2 array. actually it's the other way around... for the reason why it was introduced, @see request #5773: Decorator_Lang: append keys when fallback lang contains more than current > possible workaround is to remove the line of code or use > $data2 + $data1 instead of array_merge. with that change some tests fail. Can you try the latest CVS version, please? Thanks
 [2006-03-09 09:51 UTC] bate
It seems to work with the cvs version. My supplied patch based on my knowledge. I'd never followed the discussion why you changed something so it works now too for me i agree with you array_diff patch. :)
 [2006-03-10 21:03 UTC] quipo
> It seems to work with the cvs version. good. > My supplied patch based on my knowledge. > I'd never followed the discussion why you > changed something so it works now too for me > i agree with you array_diff patch. :) well, even if I didn't end up using your patch, thanks for reporting the issue!