ZF-5642: Zend_Form_Decorator_Errors passes invalid $errors array to formErrors when form has _elementsBelongTo set and is more than one level deep
When a sub-form has _elementsBelongTo set and utilizes the "Errors" decorator, it will throw warnings when attempting to render the errors. This is based on the following occurring:
Zend_Form_Decorator_Errors::render() calls the getMessages() on form.
When there are no messages for Zend_Form::getMessages() to process, it falls through to the last case which calls the Zend_Form::_attachToArray() function attempts to put the $messages value on to the end of an array based on Zend_Form::getElementsBelongTo() function. As we have explicitly set that value, Zend_Form::getMessages() returns an array representation of the Zend_Form::getElementsBelongTo() value.
Zend_Form_Decorator_Errors::render() then passes the array returned by Zend_Form::getMessages() to Zend_View::__call() by calling formErrors() on the view object.
Zend_View::__call() then calls Zend_View_Helper_FormErrors::formErrors() passing the array returned by Zend_Form::getMessages().
If the "escape" parameter for the helper is not set to false and the array passed to Zend_View_Helper_FormErrors::formErrors() is more than one level deep, a warning is generated when it attempts to escape the array returned in the foreach statement.
When attempting to render the array passed in as the message, the implode statement will also generate a warning as the second level of the $errors array is an array that it implode is attempting to concatenate.
I have verified that this issue occurs in all release tags from 1.6.1 and newer.