hhvm / user-documentation

Documentation for those that use HHVM and write Hack code.
http://docs.hhvm.com/
Other
129 stars 159 forks source link

Nonequivalent code snippets #1371

Open nikolatechie opened 1 month ago

nikolatechie commented 1 month ago

Where is the problem?

What is the problem?


Please don't change anything below this point.


lexidor commented 1 month ago

You are correct, $x++ is a post increment. The old value of $x gets used for the assignment. How would you like the statement to be rewritten? Should ++$x be used to restore the described behavior or should a different example be used altogether?

nikolatechie commented 1 month ago

I would suggest just removing + 1 from the second code snippet, as this example would be the easiest to understand. That would look like this:

$x = 0;
$y = $x++; // Parse error

Instead, the above code must be written as statements.

$x = 0;
$y = $x;
$x++;