Remember a mistake made because of shared variables

藏色散人
Release: 2020-10-19 14:24:56
forward
1694 people have browsed it

Below by # column for everyone to remember the mistakes of sharing variables once, I hope to help friends who need it!

Remember a mistake made because of shared variables

The problem occurs

In models/User. php

var UserModel = new (User)
Copy after login

Controller

    if models.UserModel.Token == "" {
        models.UserModel.Token = "hello world"
    }
Copy after login

Becausevar UserModel = new (User) will onlynew Once, this variable is shared with each request.

As a result, this if will only be executed once in the future, or it can only obediently new a new pointer.

obedientnew

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

Ending

It took several hoursdebug to find the problem, and I made a basic mistake.                                                                                                               

The above is the detailed content of Remember a mistake made because of shared variables. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template