ZF-3304: SubForms and their clones cannot always be modified separately

Description

Given the ZF trunk at revision 9496, cloned Zend_Form_SubForm objects behave rather unexpectedly. Specifically, it seems impossible to modify certain properties or elements of the clone without also modifying the original, and/or vice versa.

Consider the following reproduce code:


$form = new Zend_Form();
$form->setView(new Zend_View());

// Create the original SubForm
$subform1 = new Zend_Form_SubForm();
$subform1->addElement('text', 'given_name')
         ->addElement('text', 'family_name')
         ->setLegend('Me');
$form->addSubForm($subform1, 'me');

// Create a clone of the original SubForm and change it up a bit
$subform2 = clone $subform1;
$subform2->setLegend('You');
$form->addSubForm($subform2, 'you');

// Populate the form with simulated $_POST values
$postedValues = array();
$postedValues['me']['given_name']   = 'Adam';
$postedValues['me']['family_name']  = 'Jensen'; 
$postedValues['you']['given_name']  = 'Someone'; 
$postedValues['you']['family_name'] = 'Else';
$form->populate($postedValues);

// Output the finished product;
// the values and legends for both forms should be different,
// as they were set differently above.
echo $form;

The actual result looks like this (here and in the expected result, I've added some line breaks and indents for readability):



  Me   Me

Notice that the legends of both subforms are from $subform1 ("Me"), while the element values in both subforms are from $subform2 ("Someone" and "Else"). This contradicts the expected result below:



  Me   You

So...in the actual result, the values for the "me" subform are those assigned to the "you" subform, while the legend for the "you" subform is that assigned to the "me" subform. In a nutshell, we seem to have an identity crisis.

(By the way...I attempted to post this (twice) to the fw-mvc mailing list for community review, but my posting never showed up (either time). So, please forgive me if there's an easy solution to this problem that I would have found had my message gotten through to the mailing list :) )

Comments

Changing original priority; this isn't a particularly major problem, but it is a bit of an inconvenience.

Basically, we need to add a __clone() method that goes and clones each object attached to a given element, sub form, and display group... recursively. This is actually pretty tricky to achieve; I'm tentatively scheduling for 1.6, but it may be pushed to 1.7.