When many people access a class, if $ inewClass (); is explicitly written in the code, is the object accessed by all people the only $ I? When multiple users access a Class, if $ I = new Class (); is explicitly written in the code, so all people access this unique $ I?
Reply content:
When multiple users access a Class, if $ I = new Class (); is explicitly written in the code, so all people access this unique $ I?
The subject may be too clear about how the code is executed.
Essentially, you write a class, which is nothing but a set of variables and a series of functions. However, the underlying language helps you make some restrictions so that the variables or functions in this set can only be accessed and called through className. xxx.
As for your problem, you should first understand the concept of php multi-process. You can regard php code as a recipe. What is a recipe? A recipe is nothing. It is just a series of steps, so that people who see it follow its instructions to proceed to the next step. Recipes are meaningless without chefs. When the user requests to execute xxx. php, it is equivalent to a cook who takes the xxx recipe and starts cooking according to the steps written in the recipe. At the same time, there are multiple requests to xxx. php, which is equivalent to multiple chefs. What they have in common is that they share the same recipe, which means they will do the same thing later. However, each cook is independent. They have their own ingredients and pots, so they do not affect each other.
The subject may want to ask about the singleton mode. I will continue to use the example above. A cook may need to put a spoonful70% salt + 20% cumin + 10% MSG Mixture. For objects that may be used repeatedly in this way, he can place a pot in advance, and then use it without having to mix them proportionally each time. Just take a scoop from the jar directly. This is a singleton.
So you may still have questions. My computer only has one CPU for computation. What should I do if multiple requests come at the same time? Easy to use. This answer may be surprising, but it is true. It is like saying that there are 100 people who want to write compositions, but there is only one piece of paper. What should I do? You can only write two sentences for each person and then write the sentence for the next person. When everyone finishes writing the sentence, it is the first person to write the sentence. It seems that I can't write it down! But imagine that if the speed is very fast, after you write a word, your paper will be taken and written to someone else, but after 0.0000001 seconds, everyone will finish writing it, the paper goes back to your hand, and other people's handwriting is wiped clean, and the content you write is still in the original position. In such a short period of time, you do not feel the paper has been taken, you will feel that you exclusively use this paper. This is the process switching of the operating system, and PHP is also the truth.
Of course it is different. Every user has a brand new instance $ I. Because each user is in the same process.
...
If everyone gets a copy of $ I instead of executing $ I = new Class, they can return to the same instance. otherwise, if they all use $ I = new Class. it must be static. the above assumptions are that php runs in a single thread. obviously, multiple users in LZ0 will start multiple php processes.