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


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

class My_Form extends Zend_Form {
    public function init()
        $this->addSubForm($mySubform, 0);


and you clone that form:

$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:

            $name = null;
            if (!is_numeric($key)) {
                $name = $key;


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.

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

Perfect, thanks for the quick response!

Solved in branches/release-1.11 (commit 24156)