ZF-9795: Zend_Locale::isLocale() is called often, deserves local cache

Issue Type: Performance Improvement Created: 2010-05-03T09:18:43.000+0000 Last Updated: 2010-05-27T04:55:38.000+0000 Status: Resolved Fix version(s): - 1.10.5 (26/May/10)

Reporter: Alexander Grimalovsky (flying) Assignee: Thomas Weidner (thomas) Tags: - Zend_Locale

Related issues: Attachments:


Zend_Locale::isLocale() is called a lot (up to several hundred times) in a locale-aware applications, especially in multi-language applications.

Since in most cases it is being called with 1-2 values - it is possible to save some execution time by storing result of its work into local static variable and use it to return result immediately on subsequent calls with same arguments.


Posted by Thomas Weidner (thomas) on 2010-05-15T03:21:41.000+0000

Integrated with r22177

Note: Only when you use tokens which are recognised by Zend_Locale, like "en_US" the improvement will take place. In all other cases, where complete detection has to be done, the old behaviour will be used because the order could be changed in the detection rules also afterwards.

This is no neg as all locale aware classes automatically correct locale strings to those tokens and use them for further processing.

Posted by Tjebbe Westendorp (tswestendorp) on 2010-05-27T04:55:37.000+0000

Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in /*/library/Zend/Locale.php on line 811

<pre class="highlight">
        if (($locale instanceof Zend_Locale)
            || (is_array($locale) && array_key_exists($locale, self::$_localeData))
        ) {
            return true;

Isn't the following kind of strange, as array_key_exists expects a string or an integer instead of an array

is_array($locale) && array_key_exists($locale, self::$_localeData)

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.