ZF-4873: Calling isValid on a translated form swells the object size

Description

Calling isValid on a translated (using Zend_Translate) increases the size of the Zend_Form instance with the size of the translation times the number of elements in the form. With a sizeable translation-file and a larger form this could easily be from under 100kb to over 1mb. Don't know how much of a problem this is, hopefully someone of you can judge this better.

The line that causes this is: foreach ($this->getElements() as $key => $element) { $element->setTranslator($translator);

/**
 * Validate the form
 * 
 * @param  array $data 
 * @return boolean
 */
public function isValid($data)
{
    if (!is_array($data)) {
        require_once 'Zend/Form/Exception.php';
        throw new Zend_Form_Exception(__CLASS__ . '::' . __METHOD__ . ' expects an array');
    }
    $translator = $this->getTranslator();
    $valid      = true;

    if ($this->isArray()) {
        $data = $this->_dissolveArrayValue($data, $this->getElementsBelongTo());
    }

    foreach ($this->getElements() as $key => $element) {
        $element->setTranslator($translator);

Comments

This is not really a problem.

You are setting to each element a own translation object. There is no way for an element to detect if the same object has already been set to another element nor could it use this object as the elements have no connection to each other.

As generic and documented solution you should simply set a default Translator to Zend_Form which is being used when the element has no instance set.

See Zend_Form::setDefaultTranslator().

Closing as non issue as there is already a documented solution available