Home >Backend Development >PHP Tutorial >The difference between value type pointing in PHP and C#_PHP Tutorial
The difference between value copying in 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, the value of a in php is rewritten, so the php core will reassign b to an address at this time, and then copy the original value of a. 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. According to the address of the stack, find the value in the heap.