Issues

ZF-5942: Zend_Form::addSubForm assumes order of element prefix path array

Description

Zend_Form::addSubForm() iterates over the internal _elementPrefixPaths member in order to invoke Zend_Form_SubForm::addElementPrefixPath(). The latter takes three distinct arguments, which are produced by assigning the result of array_values() to a list(). If the element prefix paths have been assigned in an order other than the assumed order, the values will be transposed when calling Zend_Form_SubForm::addElementPrefixPath()

Consider the following example, where a form is created and options are passed:

$options['elementPrefixPath'] = array(
    array('type' => Zend_Form_Element::VALIDATE, 'prefix' => 'My_Validate', 'path' => APPLICATION_PATH . '/../lib/My/Validate')
);
$form = new MyFormThatHasASubForm($options);

In this scenario, the element prefix path array members are set in the order (type, prefix, path).

This is the relevant code from Zend_Form::addSubForm:

if (!empty($this->_elementPrefixPaths)) {
    foreach ($this->_elementPrefixPaths as $spec) {
        list($prefix, $path, $type) = array_values($spec);
        $form->addElementPrefixPath($prefix, $path, $type);
    }
}

When this code executes, $prefix will have the value we assigned to 'type', $path will contain 'prefix' and $type will contain 'path'.

I'm not really sure what the right answer here is, but in general it looks like Zend_Form should treat element prefix paths (in bulk) like Zend_Form_Element does.

Zend_Form_Element assumes that when assigning multiple prefix paths via Zend_Form_Element::addPrefixPaths($spec), that the $spec will be either an associative array with members 'type', 'path' and 'prefix', or an array of such associative arrays (possibly keyed on 'type'). In this case, the ordering of the array members is not really relevant, since they are looked up by key (type, path or prefix).

I imagine that Zend_Form::addElementPrefixPaths(array $spec) may also need attention.

Comments

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.