3

I have seen a question on stack over flow. What's happening with this expression? b = a + (a = a + 5)

It shows the value of b will be 15. But when i run this code on Php, value of b is 20.

Why there is difference of output in php and C#

Community
  • 1
  • 1
mjdevloper
  • 1,553
  • 8
  • 33
  • 69

1 Answers1

0

It's happens because PHP and C# differently used memory for save variables. Read How PHP manages variables. So PHP not duplicated zval memory for variable "$a" and value of $a changed when ($a = $a +5) has been completed so we have that

$a = 5;
echo $a + ($a = $a + 5);  //20

and C# has duplicated memory for a variables read answer What's happening with this expression? b = a + (a = a + 5).

Community
  • 1
  • 1
dyachenko
  • 1,216
  • 14
  • 28