Home » HTML » HTML_QuickForm » Bug #5811
Referencing in addElement
Details
| Request #5811 | Referencing in addElement |
|---|---|
| Submitted | 2005-10-28 14:26 UTC |
| From | michiel at dinnersite dot nl |
| Status | Wont fix |
| Package | HTML_QuickForm |
| PHP Version | 4.4.0 |
| OS | Linux mandrake 9.0 |
| Roadmaps | (Not assigned) |
Comments
[2005-10-28 14:26 UTC] michiel at dinnersite dot nl
Description:
------------
Version: 3.2.5
Installation: Fairly standard (only zlib and xml support added, the rest is standard).
When assinging an element that is created seperatly from QuickForm (::createElement) with addElement it creates a copy instead of a reference. This is due to the fact that the $element parameter in addElement is not passed by reference.
Of course this can't be altered due to the nature of this function (also accepting string input for the addElement function). Adding a function that allows for adding by reference (addElementByReference) would be greatly appriciated.
This was posted before as a bug under #80. Since the date on that post is more than two years ago I though I'd post the issue up again. Note that I do not whish the addElement function to be altered but the addElementByReference function to be added.
I made a custom function doing what I want to but it is a `workaround`. I'd rather see a permanent solution though. The function is posted in the testscript section.
Test script:
---------------
function addElementByReference(&$qf, &$element)
{
$element->onQuickFormEvent('updateValue', null, $qf);
$elementName = $element->getName();
// Add the element if it is not an incompatible duplicate
if (!empty($elementName) && isset($qf->_elementIndex[$elementName]))
{
if ($qf->_elements[$qf->_elementIndex[$elementName]]->getType() == $elementObject->getType())
{
$qf->_elements[] =& $element;
$qf->_duplicateIndex[$elementName][] = end(array_keys($this->_elements));
}
else
{
return PEAR::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, "Element '$elementName' already exists in HTML_QuickForm::addElement()", 'HTML_QuickForm_Error', true);
}
}
else
{
$qf->_elements[] =& $element;
$qf->_elementIndex[$elementName] = end(array_keys($qf->_elements));
}
if ($qf->_freezeAll)
{
$element->freeze();
}
return $element;
}