Home >Backend Development >PHP Tutorial >Why can't the global array be used in swoole's event callback function?
As shown in the figure, the array explicitly declared in the top-level scope cannot be called in the callback function of the onmessage event. Each time, a new array is reused and then operated. I have tried the global keyword and it does not work. It works, and adding the & reference symbol in front of the variable in use also doesn't work. What should I do?
As shown in the figure, the array explicitly declared in the top-level scope cannot be called in the callback function of the onmessage event. Each time, a new array is reused and then operated. I have tried the global keyword and it does not work. It works, and adding the & reference symbol in front of the variable in use also doesn't work. What should I do?
My understanding is that $server->on is called when the client sends information. In other words, the server will restart a process to handle the business logic.
So, whatever global and use you define are invalid.
This is called process isolation. In fact, swoole official documentation says it.