ZF-10865: Fatal error without a stack frame in Zend_Form->addElement when first argument is null

Issue Type: Patch Created: 2010-12-23T01:42:39.000+0000 Last Updated: 2012-07-30T14:37:43.000+0000 Status: Resolved Fix version(s): - 1.11.6 (05/May/11)

Reporter: Adrian Slowik (sirjedi) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Form

Related issues: - ZF-11205

Attachments: - form.patch


Method addElement of Zend_Form checks for string or Zend_Form_Element only. If someone mispell the name of variable passed to addElement, fatal error occures.


<pre class="highlight">
$form = new Zend_Form;
$form->addElement(null); // Fatal Error: Call to a member function getOrder() on a non-object [1] on line '1055' in '...\libraries\Zend\Form.php'

<pre class="highlight">
$form = new Zend_Form;
$name = $form->createElement("text", "name");
$form->addElement($nane); // - wrong variable name, error without stack frame! Fatal Error: Call to a member function getOrder() on a non-object [1] on line '1055' in '...\libraries\Zend\Form.php'


<pre class="highlight">
Index: Form.php
--- Form.php    
+++ Form.php    
@@ -1013,6 +1013,7 @@
      * @param  string|Zend_Form_Element $element
      * @param  string $name
      * @param  array|Zend_Config $options
+     * @throws Zend_Form_Exception on invalid element
      * @return Zend_Form
     public function addElement($element, $name = null, $options = null)
@@ -1050,6 +1051,9 @@
             $this->_elements[$name] = $element;
+        } else {
+            require_once 'Zend/Form/Exception.php';
+            throw new Zend_Form_Exception('Invalid element provided');
         $this->_order[$name] = $this->_elements[$name]->getOrder();


Posted by Adrian Slowik (sirjedi) on 2010-12-23T01:44:13.000+0000

Patch file

Posted by Adrian Slowik (sirjedi) on 2010-12-23T01:47:09.000+0000

Patch file

Posted by Adam Lundrigan (adamlundrigan) on 2010-12-23T17:59:54.000+0000

Thanks for your submission. I've created a new version of your patch which is relative to the repository root (this makes committing to the repository easier), added a unit test to confirm the issue, and informed the developer list it is ready for consideration.

Posted by Ralph Schindler (ralph) on 2011-05-03T03:47:59.000+0000

Fixed in trunk (by adam) at r23881 and in release branch 1.11 at 23950

Have you found an issue?

See the Overview section for more details.


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