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

Issue Type: Bug Created: 2009-01-15T02:40:27.000+0000 Last Updated: 2009-01-20T12:07:08.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Tomas Brastavicius (tomas) Assignee: Thomas Weidner (thomas) Tags: - Zend_Translate

Related issues: Attachments:


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

<pre class="highlight">
$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:

<pre class="highlight">
        $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) {


Posted by Thomas Weidner (thomas) on 2009-01-15T03:08:44.000+0000

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.

Posted by Tomas Brastavicius (tomas) on 2009-01-15T05:44:09.000+0000

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

<pre class="highlight">
    $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.

Posted by Thomas Weidner (thomas) on 2009-01-15T05:50:31.000+0000

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.

Posted by Thomas Weidner (thomas) on 2009-01-20T12:07:07.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.