Skip to main content
More indicative title
Source Link
mickmackusa
  • 49.2k
  • 13
  • 98
  • 165

Dot operator return different output than what I expected Unexpected evaluation of expression with incrementation, decrementation, multiplication, concatenation, addition-assignment, multiplication-assignment

I've been struggling to understand why this returns 252448 instead of 251248.

<?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> 

My thinking is: ++$a * $a++ gives 25 (5*5), after that we have a incremented to 6 and added to itself, so we have 12, and 12 multiplied by 4 so we get 48.

And:

<?php $a = 4; echo ++$a * $a++ . $a *= 4 . $a += $a; ?> 

returns 254944 which is even more confusing. I thought that this would return 252448 according to similar logic.

Can anybody explain to me why that is?

Dot operator return different output than what I expected

I've been struggling to understand why this returns 252448 instead of 251248

<?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> 

My thinking is: ++$a * $a++ gives 25 (5*5), after that we have a incremented to 6 and added to itself, so we have 12, and 12 multiplied by 4 so we get 48.

And:

<?php $a = 4; echo ++$a * $a++ . $a *= 4 . $a += $a; ?> 

returns 254944 which is even more confusing. I thought that this would return 252448 according to similar logic.

Can anybody explain to me why that is?

Unexpected evaluation of expression with incrementation, decrementation, multiplication, concatenation, addition-assignment, multiplication-assignment

I've been struggling to understand why this returns 252448 instead of 251248.

<?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> 

My thinking is: ++$a * $a++ gives 25 (5*5), after that we have a incremented to 6 and added to itself, so we have 12, and 12 multiplied by 4 so we get 48.

And:

<?php $a = 4; echo ++$a * $a++ . $a *= 4 . $a += $a; ?> 

returns 254944 which is even more confusing. I thought that this would return 252448 according to similar logic.

Can anybody explain to me why that is?

edited tags
Link
mickmackusa
  • 49.2k
  • 13
  • 98
  • 165
Post Closed as "Duplicate" by mickmackusa php
added 9 characters in body
Source Link
Abdulla Nilam
  • 39.7k
  • 18
  • 85
  • 115

I've been struggling to understand why this returns 252448252448 instead of 251248251248

<?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> 

My thinking is: ++$a * $a++++$a * $a++ gives 25 (5*5), after that we have a incremented to 6 and added to itself, so we have 12, and 12 multiplied by 4 so we get 48.

And:

<?php $a = 4; echo ++$a * $a++ . $a *= 4 . $a += $a; ?> 

returns 254944 which is even more confusing. I thought that this would return 252448 according to similar logic. Can

Can anybody explain to me why that is?

I've been struggling to understand why this returns 252448 instead of 251248

<?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> 

My thinking is: ++$a * $a++ gives 25 (5*5), after that we have a incremented to 6 and added to itself so we have 12, and 12 multiplied by 4 so we get 48.

And:

<?php $a = 4; echo ++$a * $a++ . $a *= 4 . $a += $a; ?> 

returns 254944 which is even more confusing. I thought that this would return 252448 according to similar logic. Can anybody explain to me why that is?

I've been struggling to understand why this returns 252448 instead of 251248

<?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> 

My thinking is: ++$a * $a++ gives 25 (5*5), after that we have a incremented to 6 and added to itself, so we have 12, and 12 multiplied by 4 so we get 48.

And:

<?php $a = 4; echo ++$a * $a++ . $a *= 4 . $a += $a; ?> 

returns 254944 which is even more confusing. I thought that this would return 252448 according to similar logic.

Can anybody explain to me why that is?

Source Link
Loading
created from staging ground