Home > Article > Backend Development > What to do if php env has no value
The solution to the problem that php env has no value: 1. Modify the configuration items of the php configuration file php.ini; 2. While putting the putenv in base.php, write the data into "$_ENV". .
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if php env has no value? PHP cannot obtain it. The value set in the env file
First: $_ENV will be empty. The reason is usually that the configuration item of the php configuration file php.ini is:
;variables_order ;Default Value: “EGPCS” ;Development Value: “GPCS” ;Production Value: “GPCS”
If you want to change the value of $_ENV Not empty:
;variables_order Default Value: “EGPCS” ;Development Value: “GPCS” ;Production Value: “GPCS”
Second:
The problem of Env not being displayed can be solved by writing data to $_ENV while puttingenv in base.php.
Open the base.php file in the thinkphp directory and modify it. Around line 41
if (is_file(ROOT_PATH . '.env')) { $env = parse_ini_file(ROOT_PATH . '.env', true); foreach ($env as $key => $val) { $name = ENV_PREFIX . strtoupper($key); if (is_array($val)) { foreach ($val as $k => $v) { $item = $name . '_' . strtoupper($k); putenv("$item=$v"); } } else { putenv("$name=$val"); //加入这一句 $_ENV[$name]=$val; } } }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if php env has no value. For more information, please follow other related articles on the PHP Chinese website!