Why are the 2 addition operations of PHP all 3?

Source: Internet
Author: User
Why do the 2 addition operations of PHP have a 3 result?
 
 $a = 1;
$c = $a + $a + +;
Var_dump ($c); Result:3

$a = 1;
$c = $a + $a + $a + +;
Var_dump ($c); Result:3


My understanding: The first result should be 2, the second result should be 3
Print output:
int 3
int 3

Share to:


------Solution--------------------
According to the syntax of PHP, your understanding is correct
and the actual result is not the case, so you can think that this is a PHP bug
Just this bug might be intentional, because that's what C is about.
------Solution--------------------
How to find a good number of posts to discuss this issue.

Wikipedia:
In computer programming, undefined behavior (English: Undefined behavior) refers to a computer code that behaves unpredictable. This is a feature of some programming languages, the most famous is in the C language. [1] In these languages, in order to simplify the standard and give a certain degree of flexibility, the standard specifically specifies that the results of certain operations are undefined, which means that the programmer cannot predict what will happen.

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