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

Bug #13176 addRow using reference inappropriately
Submitted: 2008-02-22 07:36 UTC
From: lovedub Assigned: doconnor
Status: Closed Package: HTML_QuickForm_ElementGrid (version 0.1.1)
PHP Version: 5.2.0 OS: Debian Etch
Roadmaps: (Not assigned)    
Subscription  


 [2008-02-22 07:36 UTC] lovedub (Marlin Forbes)
Description: ------------ When adding a row to an ElementGrid, the method addRow uses a reference to the row parameter. So if you're looping through a list of database results using one variable to produce a grid of elements, all rows are set to the last added row. Test script: --------------- require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm(); require_once 'HTML/QuickForm/ElementGrid.php'; $grid = new HTML_QuickForm_ElementGrid('test', 'Test'); for($index = 0; $index < 5; $index++) { $row = array( $form->createElement('checkbox', 'ch'.$index.'1'), $form->createElement('checkbox', 'ch'.$index.'2') ); $grid->addRow($row, "Row $index"); } $form->addElement($grid); $form->display(); Expected result: ----------------
Test
Row 0
Row 1
Row 2
Row 3
Row 4
Actual result: --------------
Test
Row 0
Row 1
Row 2
Row 3
Row 4
</form>

Comments

 [2008-02-22 07:40 UTC] lovedub (Marlin Forbes)
Another solution is to rather use setRows with a built array, but this is a problem when the array is very large, resulting in unnecessary storage of an interim duplicate of the element grid's rows array.
 [2008-05-05 12:11 UTC] doconnor (Daniel O'Connor)
Thanks for the patch!
 [2012-01-25 19:48 UTC] doconnor (Daniel O'Connor)
-Status: Verified +Status: Closed -Assigned To: justinpatrin +Assigned To: doconnor
This bug has been fixed in SVN. 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.