+ 2

Same same, but different

I have noticed that: //JS var x = 5; document.write(x * x++); will print 25, but //PHP $x = 5; echo $x * $x++; will output 30! now, this is something, so how a average programmer can explain this to his/her grandma?

14th Oct 2018, 6:56 AM
Dejan Dozet
Dejan Dozet - avatar
4 odpowiedzi
+ 1
It gets better, right? http://php.net/manual/en/language.operators.precedence.php You know, when it's not even consistent between versions of PHP... (rhetorical /sarcastic question).
14th Oct 2018, 9:06 AM
Janning⭐
Janning⭐ - avatar
+ 2
i have never worked with php, but this is really bad design if it's true. all other languages follow order of operation. why php?
14th Oct 2018, 8:57 AM
jay
+ 1
It depends on the level of programming knowledge of the average programmer's grandma. (I think it would be an interesting study.)
14th Oct 2018, 8:56 AM
Janning⭐
Janning⭐ - avatar
0
I have noticed this on PHP challenge playground when I and my opponent both missed the correct answer. And the one who originally posted the question offered both 25 and 30 as solution, so he knew about that already....
14th Oct 2018, 10:09 AM
Dejan Dozet
Dejan Dozet - avatar