The following code outputs 43211, why?
echo print('3').'2'.print('4');
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your statement parses to humans as follows.
Echo a concatenated string composed of:
print('3'), which will return true, which gets stringified to1print('4'), which will return true, which gets stringified to1Now, the order of operations is really funny here, that can’t end up with
43211at all! Let’s try a variant to figure out what’s going wrong.This yields
4523111PHP is parsing that, then, as:
Bingo! The
printon the left get evaluated first, printing'45', which leaves usThen the left
printgets evaluated, so we’ve now printed'4523', leaving us withSuccess.
4523111.Let’s break down your statement of weirdness.
This will print the
'4'first, leaving us withThen the next print statement is evaluated, which means we’ve now printed
'4321', leaving us withThus,
43211.I would highly suggest not
echoing the result of aprint, norprinting the results of anecho. Doing so is highly nonsensical to begin with.Upon further review, I’m actually not entirely sure how PHP is parsing either of these bits of nonsense. I’m not going to think about it any further, it hurts my brain.