duandai6373 2018-02-01 05:13
浏览 253
已采纳

未定义的变量:Laravel 5.3中的_ENV

I was testing my system with Laravel 5.3:

For past few weeks my system was working fine. Since last weekend, I encountered the same error TWICE as below:-

Notice: Undefined variable: _ENV in C:\NewFolder\htdocs\project\vendor\vlucas\phpdotenv\src\Loader.php on line 303

Warning: array_key_exists() expects parameter 2 to be array, null given in C:\NewFolder\htdocs\project\vendor\vlucas\phpdotenv\src\Loader.php on line 303

Loader.php:

public function getEnvironmentVariable($name)
{
    switch (true) {
        case array_key_exists($name, $_ENV): // line 303 here
            return $_ENV[$name];
        case array_key_exists($name, $_SERVER):
            return $_SERVER[$name];
        default:
            $value = getenv($name);
            return $value === false ? null : $value;
    }
}

.env

APP_ENV=local
APP_KEY=base64:oTU0Ok1mmE6x0qEosGKhCSxpQLAlBAnNreH7sFAKkdM=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=new_db
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_KEY=
PUSHER_SECRET=
PUSHER_APP_ID=
  • When the above error appeared on the first time(when I loaded login page), I cleared my browser cache and history, the system managed to back to normal.
  • When the same error appeared on second time(in the mid of testing process), I did the same as first time, cleared browser cache and history, but it could not helped, the error still show after I refreshed my browser. So I executed php artisan view:clear and php artisan cache:clear but still failed to get back to normal.

Anyone have any idea on why is this happening? Thanks

The version I used:

  • OS: Window 7
  • Browser: Mozilla Firefox
  • PHP: 7.1.1
  • Laravel: 5.3
  • 写回答

3条回答 默认 最新

  • doushih06137 2018-02-09 02:28
    关注

    After some finding and research, I found there are some similar issues from Github #8191.

    I able to get rid of the error by running php artisan config:cache. Means that Laravel will read the environment variable from the config file rather than reading the environment variable directly from .env

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!