Can anyone please explain to me how this works:
<?php
print 5 . print 6 . print 7;
?>
it prints: 76151
I know the 1
is the return value from the print
function, but why are the functions called in reverse order?
I believe this occurs because the dot operator is left-associative.
The expression would look like this with parenthesis:
print 5 . (print 6 . (print 7));
Your function is evaluating from right to left.
The trace is similar to this:
print (5 . print 6 . print 7)
print 7 evaluates first, printing 7 and returning 1.
print (5 . print 6 . 1)
This traces to print 61 and returning 1 Lastly:
print (5 . 1)
And thus you have 76151.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With