diff options
author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-09-12 11:15:06 +0200 |
---|---|---|
committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-09-12 11:15:06 +0200 |
commit | 8629eac3933a701d0e763b61bca80741bb5b8b82 (patch) | |
tree | 89f81590aea7c7ef000b79e43c23291e23200216 /phpBB/phpbb/language | |
parent | 2c188f22d007479477a2f5ede15a2067c7cd2242 (diff) | |
download | forums-8629eac3933a701d0e763b61bca80741bb5b8b82.tar forums-8629eac3933a701d0e763b61bca80741bb5b8b82.tar.gz forums-8629eac3933a701d0e763b61bca80741bb5b8b82.tar.bz2 forums-8629eac3933a701d0e763b61bca80741bb5b8b82.tar.xz forums-8629eac3933a701d0e763b61bca80741bb5b8b82.zip |
[ticket/14158] Add language::lang_array() to avoid using call_user_func_array
PHPBB3-14158
Diffstat (limited to 'phpBB/phpbb/language')
-rw-r--r-- | phpBB/phpbb/language/language.php | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/phpBB/phpbb/language/language.php b/phpBB/phpbb/language/language.php index 3ffb466c19..cc89e172df 100644 --- a/phpBB/phpbb/language/language.php +++ b/phpBB/phpbb/language/language.php @@ -239,15 +239,28 @@ class language */ public function lang() { + $args = func_get_args(); + $key = array_shift($args); + + return $this->lang_array($key, $args); + } + + /** + * Act like lang() but takes a key and an array of parameters instead of using variadic + * + * @param string|array $key Language key + * @param array $args Parameters + * + * @return array|string + */ + public function lang_array($key, $args = []) + { // Load common language files if they not loaded yet if (!$this->common_language_files_loaded) { $this->load_common_language_files(); } - $args = func_get_args(); - $key = $args[0]; - if (is_array($key)) { $lang = &$this->lang[array_shift($key)]; @@ -271,26 +284,25 @@ class language // If the language entry is a string, we simply mimic sprintf() behaviour if (is_string($lang)) { - if (sizeof($args) == 1) + if (count($args) === 0) { return $lang; } // Replace key with language entry and simply pass along... - $args[0] = $lang; - return call_user_func_array('sprintf', $args); + return vsprintf($lang, $args); } else if (sizeof($lang) == 0) { // If the language entry is an empty array, we just return the language key - return $args[0]; + return $key; } // It is an array... now handle different nullar/singular/plural forms $key_found = false; // We now get the first number passed and will select the key based upon this number - for ($i = 1, $num_args = sizeof($args); $i < $num_args; $i++) + for ($i = 0, $num_args = sizeof($args); $i < $num_args; $i++) { if (is_int($args[$i]) || is_float($args[$i])) { @@ -337,8 +349,7 @@ class language } // Use the language string we determined and pass it to sprintf() - $args[0] = $lang[$key_found]; - return call_user_func_array('sprintf', $args); + return vsprintf($lang[$key_found], $args); } /** |