Home  >  Article  >  Backend Development  >  What to do if php env has no value

What to do if php env has no value

藏色散人
藏色散人Original
2021-06-11 09:26:531983browse

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". .

What to do if php env has no value

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn