In PHP, what is the relationship between $ a and $ GLOBALS ['a'] in memory?

Source: Internet
Author: User
{Code ...} $ a and $ GLOBALS [& #039; a & #039;] The relationship in memory is definitely not like this. If so, unset ($ GLOBALS [& #039; a & #039;]) $ a should still be solved. Thank you very much.
$a=4;unset($GLOBALS['a']);var_dump($a);

What is the relationship between $ a and $ GLOBALS ['a'] in memory?

Certainly not.

In this case, unset ($ GLOBALS ['a']) $ a should still exist.
Thank you very much for solving this problem.

Reply content:
$a=4;unset($GLOBALS['a']);var_dump($a);

What is the relationship between $ a and $ GLOBALS ['a'] in memory?

Certainly not.

In this case, unset ($ GLOBALS ['a']) $ a should still exist.
Thank you very much for solving this problem.

GLOBALS is a super global variable and itself is an associated array. All global variables are a key-Value Pair
So
Execute outside the Function,unset($GLOBALS['a']);Andunset($a);Is completely equivalent
Execute in the function, You need to consider the scope issue, if you passglobal $a;When this environment variable is introduced, it is executed in the function.unset($GLOBALS['a']);It will also affect the function$aAccess and use

See
Http://php.net/manual/zh/reserved.variables.globals.php

Supplementary content
The memory of the question in the comments is such that the relationship between the two variables cannot be understood in the form of C variables and pointers. After obtaining your variable name, PHP searches for the specific address in the symbol table (a hash table) of the current context. If you are outside the function, the symbol table in your current context is the global symbol hash table pointed to by GLOBALS. You can read the zend in php source code. c and zend_compile.c to understand how the zend engine processes global variables.

First, you need to understandunsetIt is different in the function execution and out-of-function execution;
For details, see unset

According to your code,unsetWill be destroyed at the same time$aAnd$GLOBALS['a'];

However$aAnd$GLOBALS['a']It is two independent variables, not references. One is a common variable and the other is a global variable.

Local variables are stored in active_symbol_table.
Global variables are stored in symbol_table.
Apart from saving local variables and global variables in different symbol tables, they are identical in the php kernel.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.