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?
1 Answer
Reset to default 2The 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';