PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_Page2 » Bug #2054

page content is copied unnecessarily

Details

Request #2054page content is copied unnecessarily
Submitted2004-08-04 15:16 UTC
Fromthomas-frank at gmx dot de
Assignediwarner
StatusClosed
PackageHTML_Page2
PHP Version4.3.3
OSLinux
Roadmaps(Not assigned)

Comments

[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.

[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();
...
}

[2006-11-01 04:18 UTC] iwarner at php dot net

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.