From 8629eac3933a701d0e763b61bca80741bb5b8b82 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 12 Sep 2015 11:15:06 +0200 Subject: [PATCH 1/2] [ticket/14158] Add language::lang_array() to avoid using call_user_func_array PHPBB3-14158 --- phpBB/phpbb/language/language.php | 31 +++++++++++++++++++++---------- 1 file 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 @@ -238,6 +238,22 @@ class language * @return string Return localized string or the language key if the translation is not available */ 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) @@ -245,9 +261,6 @@ class language $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); } /** From 8aa8173ebfcd1f00d26f9a3dde5a7101579f2ed2 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 12 Sep 2015 15:14:42 +0200 Subject: [PATCH 2/2] [ticket/14158] Fix 5.3 compatibility PHPBB3-14158 --- phpBB/phpbb/language/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/language/language.php b/phpBB/phpbb/language/language.php index cc89e172df..47f055f56a 100644 --- a/phpBB/phpbb/language/language.php +++ b/phpBB/phpbb/language/language.php @@ -253,7 +253,7 @@ class language * * @return array|string */ - public function lang_array($key, $args = []) + public function lang_array($key, $args = array()) { // Load common language files if they not loaded yet if (!$this->common_language_files_loaded)