记一次因为共享变量的犯错误

问题复现

在models/User.php

var UserModel = new (User)

控制器

    if models.UserModel.Token == "" {
        models.UserModel.Token = "hello world"
    }

因为 var UserModel = new (User) 只会new 一次,每个请求都共享的这个变量的。

导致以后这个 if 只会执行一次,还是只能乖乖的 new 一个新的指针。

乖乖的 new

    var UserModel = new (models.User)
    if UserModel.Token == "" {
        UserModel.Token = "hello world"
    }

结尾

花费几小时 debug 才找到问题的,犯了基础的错误。

本作品采用《CC 协议》,转载必须注明作者和本文链接
专心学习不瞎搞
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
87
粉丝
105
喜欢
480
收藏
717
排名:109
访问:8.7 万
私信
所有博文
社区赞助商