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

Issue Type: Bug Created: 2009-03-04T12:30:21.000+0000 Last Updated: 2012-11-20T20:53:11.000+0000 Status: Closed Fix version(s): Reporter: Chris Abernethy (brownoxford) Assignee: None Tags: - Zend_Form

Related issues: Attachments:


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.


Posted by Rob Allen (rob) on 2012-11-20T20:53:11.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.