PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_Page » Bug #950

[Patch] Correct iterative recustion

Details

Submitted2004-03-05 16:29 UTC
Fromdostick at ctco dot lv
Assignedthesaur
StatusClosed
PackageHTML_Page
PHP Version4.3.4
OSUNIX
Roadmaps(Not assigned)

Comments

[2004-03-05 16:29 UTC] dostick at ctco dot lv

Description:
------------
This patch fixes the recursion in generateBody
Now page support mixed colelction of objects and arrays in _body. If it's an array its iterated recirsively,
if it's an object, toHtml/toString is caleld and result of it is processed recursively.
So, If $element->toHtml() produces an array, it will be correctly processed.
patch against latest version from cvs:

--- Page.orig Fri Mar 5 14:51:18 2004
+++ Page.php Fri Mar 5 18:32:39 2004
@@ -346,15 +346,14 @@
* extend HTML_Common.
*
* @access protected
- * @param array $array The array to be processed
+ * @param mixed $element The element to be processed
* @return string
*/
- function _arrayToHtml(&$array) // It's a reference just to save some memory.
+ function _elementToHtml(&$element) // It's a reference just to save some memory.
{
$lnEnd = $this->_getLineEnd();
$tab = $this->_getTab();
$strHtml = '';
- foreach ($array as $element) {
if (is_object($element)) {
if (is_subclass_of($element, 'html_common')) {
$element->setTabOffset(1);
@@ -363,21 +362,22 @@
}
if (is_object($element)) {
if (method_exists($element, 'toHtml')) {
- $strHtml .= $element->toHtml() . $lnEnd;
+ $strHtml .= $this->_elementToHtml($element->toHtml()) . $lnEnd;
} elseif (method_exists($element, 'toString')) {
- $strHtml .= $element->toString() . $lnEnd;
+ $strHtml .= $this->_elementToHtml($element->toString()) . $lnEnd;
}
} else {
$strHtml .= $tab . $element . $lnEnd;
}
} elseif (is_array($element)) {
- $strHtml .= $this->_arrayToHtml($element);
+ foreach ($element as $item) {
+ $strHtml .= $this->_elementToHtml($item);
+ }
} else {
$strHtml .= $tab . $element . $lnEnd;
}
- }
return $strHtml;
- } // end func _arrayToHtml
+ } // end func _elementToHtml

/**
* Generates the HTML string for the <body< tag
@@ -404,7 +404,7 @@

// Allow for mixed content in the body array, recursing into inner
// array serching for non-array types.
- $strHtml .= $this->_arrayToHtml($this->_body);
+ $strHtml .= $this->_elementToHtml($this->_body);

// Close tag
$strHtml .= '</body>' . $lnEnd;

[2004-03-25 00:13 UTC] thesaur at php dot net

Patch has been applied to CVS. It will be included in the next release.

Thank you for your work.