From 6e2bab02cca0bd4b212d98414e56b784a8ff92ff Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 18 Dec 2023 21:19:33 +0900 Subject: [PATCH] Be more permissive about null values passed to lang() and Context::getLang() --- classes/context/Context.class.php | 2 +- common/functions.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index ceea05a3f..a1823b40d 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -856,7 +856,7 @@ class Context $GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common'); } - return $GLOBALS['lang']->get($code); + return $code ? $GLOBALS['lang']->get((string)$code) : (string)$code; } /** diff --git a/common/functions.php b/common/functions.php index 98555cc2c..ae2616abe 100644 --- a/common/functions.php +++ b/common/functions.php @@ -32,7 +32,7 @@ function config(string $key, $value = null) * @param string $value `$code`s value * @return string|null|\ArrayObject */ -function lang(string $code, $value = null) +function lang(?string $code, $value = null) { if (!isset($GLOBALS['lang']) || !$GLOBALS['lang'] instanceof Rhymix\Framework\Lang) { @@ -42,9 +42,9 @@ function lang(string $code, $value = null) if ($value === null) { - return $GLOBALS['lang']->get($code); + return $GLOBALS['lang']->get($code ?? ''); } - else + elseif ($code !== null) { $GLOBALS['lang']->set($code, $value); }