ZF-11504: Zend_From::addSubForms() issue after cloneing

Issue Type: Bug Created: 2011-06-23T14:40:01.000+0000 Last Updated: 2011-06-27T14:59:50.000+0000 Status: Resolved Fix version(s): - 1.11.8 (07/Jul/11)

Reporter: Brandon Mueller (fatmuemoo) Assignee: Enrico Zimuel (zimuel) Tags: - Zend_Form

Related issues: Attachments:


If you have a form with a subform with a name of numerical value

<pre class="highlight">
class My_Form extends Zend_Form {
    public function init()
        $this->addSubForm($mySubform, 0);


and you clone that form:

<pre class="highlight">
$form = new My_Form();
$form2 = clone $form;

you will get the following exception: "Invalid name provided; must contain only valid variable characters and be non-empty"

reason being the __clone method uses the addSubForms method and in the addSubFroms method it sets the $name = null and then never sets it to anything else unless the $key is a string. As you can see, the addSubfrom method allowed me to add a subform with a numeric name, therefore it is logical that the addSubForms() method would do the same.

If you remove line 1645-1648 of Zend_Form, it solves the problem:

<pre class="highlight">
            $name = null;
            if (!is_numeric($key)) {
                $name = $key;


Posted by Enrico Zimuel (zimuel) on 2011-06-27T10:22:14.000+0000

I agree, the addSubForm() allows you to specify a numeric value as name, this means that addSubForms() should have the same behaviour. I will provide a fix and a unit test for that, thanks.

Posted by Enrico Zimuel (zimuel) on 2011-06-27T11:21:51.000+0000

Solved in trunk (commit 24155). Try it and let me know, thanks.

Posted by Brandon Mueller (fatmuemoo) on 2011-06-27T12:02:04.000+0000

Perfect, thanks for the quick response!

Posted by Enrico Zimuel (zimuel) on 2011-06-27T14:59:21.000+0000

Solved in branches/release-1.11 (commit 24156)

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.