About the strange problem of PHP's value-to-pass and reference

Source: Internet
Author: User
Strange questions about PHP values and citations
PHP Code
  
  $a = 1; $b = & $a; $b = $a ++;echo $b. "
"; Echo $a;

Who can tell me what the last $ A and $b results are and why is this result?

------Solution--------------------
I think it's strange: Why do you always have to digest bugs yourself?
This has been a problem for many years, but no one has ever reported this bug
Analysis of specific reasons need to look at the source, but it is too difficult to locate the

by syntax $a + + is equivalent to $a = $a + 1
So
$b = $a + +;
Equivalent to
$b = $a;
$a = $a + 1;

If there are no previous references
$b = & $a;
echo $a;
Is can get the right result 2 of the

As a result of the reference, the rules changed. This is obviously wrong!
This is a bug when implementing a reference in PHP
Of course, he may also be aware of the problem, but can not solve

In short, because of this bug, you try not to explicitly use the reference

  • 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.