Remember a mistake made because of shared variables

藏色散人
Release: 2020-10-19 14:24:56
forward
1646 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 onlynewOnce, this variable is shared with each request.

As a result, thisifwill only be executed once in the future, or it can only obedientlynewa new pointer.

obedientnew

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

Ending

It took several hoursdebugto 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!