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

Request #2054 page content is copied unnecessarily
Submitted: 2004-08-04 15:16 UTC
From: thomas-frank at gmx dot de Assigned: iwarner
Status: Closed Package: HTML_Page2
PHP Version: 4.3.3 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2004-08-04 15:16 UTC] thomas-frank at gmx dot de
Description: ------------ In HTML_Page2::_generateBody() and here in HTML_Page2::_elementToHtml(): If the element is an array you iterate through the items with 'foreach', which creates a copy of each array item, before finally calling e.g. toHtml() on the item.

Comments

 [2004-08-04 15:24 UTC] thesaur
As far as I know, PHP does not actually copy the content of a variable unless it is changed. Do you have any data that shows that it really increases memory usage? Also, do you have a better solution? Afaik, this issue will be pretty much moot anyway once we get to php5, which uses references for objects by default.
 [2004-08-05 07:02 UTC] thomas-frank at gmx dot de
I think a problem may arise e.g. if one manipulates larger amounts of member data within the toHtml() of an Object. OK - this may not be a good design, but I think one shouldn't be forced to take care of this anyway. When I call addBodyContent() explicitly with a reference, I expect that HTML_Page2 stores and uses exclusively this reference. One general solution to avoid copies on array iteration is e.g.: $myArray=array( ... ); ... foreach ( array_keys( $myArray ) as $k ) { do_something_with( &$myArray[$k] ); echo $myArray[$k]->toHtml(); ... }
 [2005-03-24 18:44 UTC] thesaur
Sorry for the long wait. Yes, that makes absolute sense. I will implement and release hopefully soon.
 [2006-11-01 04:18 UTC] iwarner at php dot net (Ian Warner)
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.