Home  >  Article  >  Backend Development  >  A brief discussion on the detailed explanation of the difference between value type pointing in PHP and C#_PHP Tutorial

A brief discussion on the detailed explanation of the difference between value type pointing in PHP and C#_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:10:15790browse

The difference between value copying in PH and C# (if something is wrong, please point it out!)
$a = 2;
$b = $a; //In php, point the address of b here to a, so b It is also equal to 2 at this time; the difference is here
$a = 5; //At this time, the value of a in php is rewritten, so the php core will reassign b to an address at this time, and then change a to the original address. The value is copied. This is the principle of copy-on-write, which means that unless a write operation is performed, the value type points to an address.
And in C#. Copy of value types. Always create a new address, such as:
int a = 2;
int b = a; // At this time, it does not matter whether a is written twice or not. .NET will allocate a new memory space to b (the value is stored in the stack space). Then copy the value of a
Note: In C#, values ​​of value types are stored directly on the stack. For reference types, the reference address is stored on the stack, and the actual value is stored on the heap. Find the value in the heap according to the address of the stack.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327129.htmlTechArticleDifferences in value copying between PH and C# (if something is wrong, please point it out!) $a = 2; $b = $a; //In php, the address of b points to a, so b is also equal to 2 at this time; the difference is here$a = 5; //At this time...
Statement:
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