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 #1341

Call to a member function on a non-object

Details

Submitted2004-05-04 21:18 UTC
Frommichael at mompopmedia dot com
StatusBogus
PackageHTML_QuickForm
PHP Version4.3.5
OSlinux
Roadmaps(Not assigned)

Comments

[2004-05-04 21:18 UTC] michael at mompopmedia dot com

Description:
------------
Hi,

I'm using HTML_QuickForm 3.2.2 and am trying to create a group of radio input items:

$gender[] = &HTML_QuickForm::createElement('radio', 'gender', '', 'male');
$gender[] = &HTML_QuickForm::createElement('radio', 'gender', '', 'female');
$form->addGroup($gender, 'gender', 'Gender:', ' ');

They display fine, but on submit I get the following fatal error:

Fatal error: Call to a member function on a non-object in /vhome/ecohosti/public_html/survey/mole/lib/HTML/QuickForm/group.php on line 386

It appears that the array of elements that is looped through at this point in the code is being poulated with the following bogus array item (all following items are proper element objects)

[0]=> string(2) "on"

To deal with the problem, i added the following at line 385:

if (is_object($this->_elements[$key])) {

and a closing brace at line 395

Thanks.

Reproduce code:
---------------
foreach (array_keys($this->_elements) as $key) {
if (is_object($this->_elements[$key])) {
if ($this->_appendName) {
$elementName = $this->_elements[$key]->getName();
if (is_null($elementName)) {
$this->_elements[$key]->setName($this->getName());
} elseif ('' == $elementName) {
$this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
} else {
$this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
}
}
$this->_elements[$key]->onQuickFormEvent('updateValue', $arg, $caller);
if ($this->_appendName) {
$this->_elements[$key]->setName($elementName);
}
}
}

[2004-05-04 21:20 UTC] michael at mompopmedia dot com

actually, I take my fix back. similar logic would need to be applied else where too.