For PHP programmers, as different versions of PHP update and improve some function variable mechanisms, it often causes confusion when using the same variable in different versions produces different results. So this article mainly explains to you in detail why different results occur when using the same global variable under PHP5 and PHP7 versions? Let me give you a simple and easy-to-understand example.
For example, the existing exl.php page operation code is as follows:
#The result we ran in the local php5 version environment is 5, as shown in the screenshot below :
Then the result of running it in the php7 version environment is 3, as shown in the screenshot below:
The reason why Different operation results will appear. This is actually because in the latest php7 version, the PHP global variable processing mechanism has been modified. In this version, the global keyword can now only refer to simple variables. So when we operate in the local php5 version environment, the output value of $y is $x+$y=5. At this time, global is equivalent to the use of global variables. In the php7 environment, the output value of $y is $y=3. At this time, the global variable can only directly reference the simple variable $y.
So through the above sample code explanation, I hope that this article about the problem of global variables in PHP producing different results when operating in different versions will be helpful to everyone when encountering related problems. I also hope that everyone can pass this article. This article provides an understanding of the usage of php global under different versions.
[Recommended related articles]
Why do global variables become invalid or wrong?
Some different understandings of global and $GLOBAL['']
Global keyword in PHP source code analysis