Home > Article > Backend Development > About the mystery of self-increment and self-decrement operations in PHP_PHP Tutorial
First look at an interview question:
$a = 1; $b = &$a; if ($b == $a++) echo "true"; else echo "false";
Then, a variable $b is created and used as a reference to $a;
The last judgment statement contains two opcodes: POST_INC and IS_EQUAL. The first thing to execute is the return first and then increment statement (POST_INC), which returns 1 first, and then $a increments to 2, because $b is a reference to $a, and $b is also 2. Then the comparison statement (IS_EQUAL) is executed, because the value of $b is 2 and the return value of $a++ is 1, so they are not equal.
Similar interview questions include:
$a = 1; $b = &$a; $b = $a++; echo "a: $a; b: $b";