Issues

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

Issue Type: Improvement Created: 2011-03-22T09:52:48.000+0000 Last Updated: 2012-07-30T14:38:00.000+0000 Status: Closed Fix version(s): Reporter: Lee Davis (leedavis81) Assignee: Frank Br├╝ckner (frosch) Tags: - Zend_Form

Related issues: - ZF-10865

Attachments:

Description

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..

<pre class="highlight">
$form = new Zend_Form();
$form->addElement(null);

Gives:

<pre class="highlight">
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:

<pre class="highlight">
$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..

<pre class="highlight">
$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.

<pre class="highlight">
if (!is_null($element))
{
        $this->_order[$name] = $this->_elements[$name]->getOrder();
        $this->_orderUpdated = true;
        $this->_setElementsBelongTo($name);
}

Comments

Posted by Kai Uwe (kaiuwe) on 2011-03-22T10:17:53.000+0000

Code tags added

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts