Questions about PHP variables

Source: Internet
Author: User
PHP variable Issues
$b = ' AAA ';
$a =& $b;
$b = ' DDD ';
Unset ($b);
echo $a;


Output DDD at this time;
Question: $a =& $b; This is to assign the memory address of variable B to $ A, and change the value of B to a.

Unset ($b) destroyed the variable B;echo $a why is it possible to output a value?

------Solution--------------------
$b = ' DDD ' has changed the memory address of the $b.
------Solution--------------------
You first $a=& $b, in fact, a $ A stealth to $b address, you unset ($b) only after the $b and the value of the mapping relationship is canceled, and does not affect a $ A

I wonder if the description is clear ... Cold,, long time not to do PHP long not to come up to irrigation, expression ability has become worse
------Solution--------------------
PHP Code
From the C point of view, the structure of the $a this variable contains a pointer to the $b variable, that is, $ A to save the $b variable address,//unset ($b), the PHP engine does not really release the content of this address, the time of the release of the variable should be determined by the engine's memory recovery mechanism $b = ' AAA '; $a = & $b; $c = & $b;//Add a reference here, perhaps the PHP engine also takes this into account, so do not immediately release the variable//when memory fragmentation is too much, it will be recycled and reused, to avoid repeated application of small block memory, reduce efficiency $b = ' CCC '; unset ($b); $c = ' ddd '; unset ($c); Echo ' $a  '. $a;//output ddd//above only conjecture, for reference only
  • 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.