how to solve PHP Parse error: syntax error, unexpected token "echo" in php shell code on line 2 in interactive

admin2025-04-16  2

I opened an interactive PHP shell using php -a and started entering the statements

php > "12" == 12
php > echo "12" == 12
php > echo ("12" == 12)
php > echo ("12" == 12);

And then I got the error

PHP Parse error:  syntax error, unexpected token "echo" in php shell code on line 2

I was expecting to get true or false, why doesn't the interactive shell tell me what the value of "12" = 12 is?

I opened an interactive PHP shell using php -a and started entering the statements

php > "12" == 12
php > echo "12" == 12
php > echo ("12" == 12)
php > echo ("12" == 12);

And then I got the error

PHP Parse error:  syntax error, unexpected token "echo" in php shell code on line 2

I was expecting to get true or false, why doesn't the interactive shell tell me what the value of "12" = 12 is?

Share Improve this question asked Feb 3 at 12:59 camilajennycamilajenny 5,0946 gold badges35 silver badges67 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

The error was because I didn't finish the instructions, so the interactive shell interpreted my statements as one long instruction

"12" == 12 echo "12" == 12 echo ("12" == 12) echo ("12" == 12);

which has a syntax error on the first echo.

The solution is to end the instruction with a semicolon

 echo "12" == 12 ? 'true' : 'false';
转载请注明原文地址:http://www.anycun.com/QandA/1744770520a87383.html