Answer the question
In order to leave comments, you need to log in
A useless question about print(), why does it get what it does?
learned that print() returns 1, decided to play.
If you do $a = 1 + print("3"); echo ++$a;
that, 33 will be displayed on the screen, everything is correct: the first triple was displayed by print and returned 1, a = 1 + 1, and the second triple was displayed through the increment.
But if you swap 1 and print, then everything will be a little different: it $a = print("3") + 1; echo ++$a;
will print 42!
Changing the places of terms affects type casting, but what is happening here is still not clear.
Somehow the +1 moved inside print() which I find funny, are there any gurus here who understand how it works?
Answer the question
In order to leave comments, you need to log in
print is not a "real" function (it's a language construct), so it's not necessary to enclose arguments in parentheses.
In the first case, everything is obvious: 33.
In the second case, it will be like this: print(("3") + 1). Therefore, 4 will be displayed. Then 2 is also obvious.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question