我正在尝试将 json 文件中的值分配给某种全局/静态变量,然后稍后在文件中使用该全局/静态变量。
static $API_KEY = get_api_key(); // gives: Constant expression contains invalid operations
define('API_KEY', get_api_key()); // gives: PHP Notice: Undefined variable: API_KEY in /content.php on line 422
function get_api_key() {
$file_content = file_get_contents("./msx/start.json");
$json = json_decode($file_content);
return $json->tmdb_api_key;
}