ZF-11205: Adding a null element to a zend form object produces fatal error on member function getOrder()


If adding solely a null element to a zend form object I believe it should function in the manner as adding a null element to a zend form object that already has an element.

for example..

$form = new Zend_Form();


Fatal error:
Call to a member function getOrder() on a non-object in /library/Zend/Form.php on line 1052

However, this produces a valid form:

$form = new Zend_Form();
$a = new Zend_Form_Element_Text('textfield');
$form->addElement($a, null);

Further to this, switching the order of the elements around also causes the same fatal error, along with with an Illegal offset type on the same line.

Like so..

$form = new Zend_Form();
$a = new Zend_Form_Element_Text('textfield');
$form->addElement(null, $a);

I propose two solutions:

Firstly: We throw an exception when a null element is attempted on a form object.

Secondly (preference): We allow form objects to gracefully handle any null element attempted on it. And nothing is produced when attempting to echo those elements from the form. This can be achieved by wrapping lined 1052 - 1054 on Zend/Form.php in a null test.

if (!is_null($element))
        $this->_order[$name] = $this->_elements[$name]->getOrder();
        $this->_orderUpdated = true;


Code tags added