Zend Framework

Translate_Adapter throws warning if $messageId is object

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.5
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Translate
  • Labels:
    None

Description

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;

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Michal Vrchota added a comment - - edited

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

Show
Michal Vrchota added a comment - - edited 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
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Thomas Weidner added a comment -

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

Show
Thomas Weidner added a comment - Notices are no longer given with r19367. Exceptions will not be integrated for translation.
Hide
Renat Ismagilov added a comment -

Translate_Adapter still throws warnings by isTranslated method:

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

should be fixed also.

Show
Renat Ismagilov added a comment - Translate_Adapter still throws warnings by isTranslated method: if (isset($this->_translate[$locale][$messageId]) === true) { // return original translation return true; } should be fixed also.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: