ZF-12439: Error message code produces array to string conversion error
Description
Going $element->setError('string') when $element->getValue() is an empty array causes an array to string conversion notice.
Culprit is this code:
protected function _getErrorMessages()
{
$translator = $this->getTranslator();
$messages = $this->getErrorMessages();
$value = $this->getValue();
foreach ($messages as $key => $message) {
if (null !== $translator) {
$message = $translator->translate($message);
}
if (($this->isArray() || is_array($value))
&& !empty($value)
) {
$aggregateMessages = array();
foreach ($value as $val) {
$aggregateMessages[] = str_replace('%value%', $val, $message);
}
$messages[$key] = implode($this->getErrorMessageSeparator(), $aggregateMessages);
} else {
$messages[$key] = str_replace('%value%', $value, $message);
}
}
return $messages;
}
The problem is the !empty($value) causes the code to execute the second branch of the if() clause, as empty(array()) === true.
Comments
Posted by Rob Allen (rob) on 2012-11-16T15:45:59.000+0000
Does this patch fix it?
Posted by Rob Allen (rob) on 2012-12-22T20:05:40.000+0000
Fixed on trunk (25172) and release-1.12 (25173)