PEAR is archived and read-only

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

Home » HTML » HTML_QuickForm » Bug #2726

Group elements not freezing if group already frozen

Details

Submitted2004-11-10 03:08 UTC
Frommichael at baselinesols dot com
Assignedavb
StatusClosed
PackageHTML_QuickForm
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-11-10 03:08 UTC] michael at baselinesols dot com

Description:
------------
HTML_Quickform version: 3.2.4pl1

If a class that extends HTML_QuickForm_group (eg HTML_QuickForm_date) is instanciated and then frozen (using freeze()) before the _createElements() method is called, then the elements that are created during _createElements() are not frozen.

The main side effect of this is incorrect HTML generation if the accept() or toHtml() methods are called.

There are a number of ways to overcome this (sorry for posting code in this section, but it needs explanation):

1. When the freeze() method is called in HTML_QuickForm_group, make sure that _createElements() is called before proceeding with freezing each element:

if (empty($this->_elements)) {
$this->_createElements();
}
...

2. Each sub-class of HTML_QuickForm_group must explictly freeze the element after creating it in _createElements() (IMO this is the most "correct" and fastest method). Eg, for HTML_QuickForm_date::_createElements():

...
$next_element =& new HTML_QuickForm_select($sign, null, $options, $this->getAttributes());
if ($this->_flagFrozen) {
$next_element->freeze();
}
$this->_elements[] =& $next_element;
...

3. Check if the group is frozen and explicitly call freeze in HTML_QuickForm_group::_createElements() - and then sub-classes would call parent::_createElements() method at the end of their _createElements() method.

And there are probably a number of other ways that this can be done too.

The main problem with choice 2 is that it leaves it up to the sub-class to take responsibility for correctly freezing each newly created element - if there was any way the HTML_QuickForm_group class could do this, then possibly that would be preferrable.