Questions about how to pass PHP values and pass references

Source: Internet
Author: User
PHPcode $ a1; $ B & amp; $ a; $ B $ a ++; echo $ B. & quot; & lt; br & gt; & quot; echo $ a; who can tell me what the final results of $ a and $ B are and why? ------ Solution ------------------ what I think is strange is: why is it always a strange question about passing values and references in PHP?
PHP code
  $ A = 1; $ B = & $ a; $ B = $ a ++; echo $ B ."
"; Echo $;

Who can tell me what the final result of $ a and $ B is and why?

------ Solution --------------------
I think the strange thing is: why always digest bugs by yourself?
This problem has been around for many years, but no one has ever reported this bug.
To analyze the specific cause, you need to look at the source code, but it is too difficult to locate it.

According to the syntax, $ a ++ is equivalent to $ a = $ a + 1.
That is to say
$ B = $ a ++;
Equivalent
$ B = $;
$ A = $ a + 1;

If there is no previous reference
$ B = & $;
Echo $;
Yes. expected result 2 is displayed.

With the reference, the rule changes. This is obviously wrong!
This is a bug in php implementation reference.
Of course, he may be aware of the problem but cannot solve it.

In short, because of the existence of this bug, you should 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.