ZF-5551: Zend_Translate_Adapter::setOptions() sets disable_notices option after the option was used


Zend_Translate_Adapter::setOptions() uses foreach to loop over the options arrays. Assume the following options array:

$options = array(
     'locale' => 'en',
     'disable_notices' => true

On the first loop foreach executes setLocale() method which in turn may use disable_notices option to disable/enable throwing a notice. But disable_notices option is set on the second loop, therefore an 'old' value was used.

My proposal is to replace foreach with the following code:

        $locale = false;
        foreach ($options as $key => $option) {
            if ($key == "locale") {
                $locale = $option;
            } else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or
                    !isset($this->_options[$key])) {
                $this->_options[$key] = $option;
                $change = true;
        if($locale !== false) {


setOptions() is not a static method. It is called at initiation and set when reading the translation file.

To disable notices afterwards in the mid of a script execution is really a no-go which leads to problems in normal cases.

It is not necessary to call setOptions() in the mid of a script. The same applies to the following code:

    $options = array(
        'locale' => 'en',
        'disableNotices' => true
    $Translate = new Zend_Translate(Zend_Translate::AN_GETTEXT, '/path/to/lang/', 'lt', $options);

I encountered the issue on the test script of my application. I agree that it is not a normal case.

Maybe... but also the second example will not work.

You are giving "lt" and "en" as locale at initiation... now which one should the adapter use ? In this case the notice even makes sense as you are not allowed to set two locales at once.

Behaviour changed with r13715.

BUT: Setting multiple options with the same method call, when these options are dependent from each other is not supported.

THIS MEANS: When options dependent from each other are given you must seperate them.