Home headlines What are the changes in the global variable mechanism under PHP5 and PHP7? (Code actual test)

What are the changes in the global variable mechanism under PHP5 and PHP7? (Code actual test)

Aug 09, 2018 pm 12:14 PM
global variables

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:

What are the changes in the global variable mechanism under PHP5 and PHP7? (Code actual test)

#The result we ran in the local php5 version environment is 5, as shown in the screenshot below :

What are the changes in the global variable mechanism under PHP5 and PHP7? (Code actual test)

Then the result of running it in the php7 version environment is 3, as shown in the screenshot below:

What are the changes in the global variable mechanism under PHP5 and PHP7? (Code actual test)

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

global and $GLOBALS in php


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)