ZF-8448: Translate_Adapter throws warning if $messageId is object


Sometimes object is passed to the $messageId (i.e. via Zend_Form instance of class with toString() magic method is passed as value) however that $messageId is not translated and gives

PHP Warning: Illegal offset type in isset or empty in /home/www/app/library/Zend/Translate/Adapter.php on line 682

This should fix the problem if (is_object($messageId)) $messageId = (string)$messageId;


Zend_Translate MUST have an string as key. Other types are not allowed and should not be given.

Using toString implicitly by isTranslated() would add problems. In my opinion it's better to have this warning to force the user to prevent those problems.

The thing is, that it is very difficult to track down the source code - where the object was passed. So I suggest to throw an exception instead.

IMHO 1 exception (which can be easily tracked) is better then thousands of pointless warnings in php error log

I agree on the notice being suppressed. But I do not agree on throwing an exception while translating.

Calling "translate()" it is NOT ALLOWED to throw an exception in any case. The return value must be equal with the input when no translation can be done.

Notices are no longer given with r19367. Exceptions will not be integrated for translation.

Translate_Adapter still throws warnings by isTranslated method:

    if (isset($this->_translate[$locale][$messageId]) === true) {
        // return original translation
        return true;

should be fixed also.