2

I'm learning to use the PHP interactive shell, but I'm having trouble with multi-line code.

Using backslashes like in the UNIX shells doesn't seem to work. What am I doing wrong ?

php > function test(){\
php { echo "test";\
php { }\
php > test();
PHP Parse error:  syntax error, unexpected T_ECHO, expecting T_STRING in php shell code on line 2

1 Answer 1

2

Just don't escape it:

php > function test()
php > {
php {   echo "test";
php { }
php > test();
test

However, you will have problems in certain cases, such as:

php > if(conditional)
php > {
php {   // ...
php { }
php > else
php > {
php {   // ...
php { }

It thinks the if is over before it sees the else, so you get a "unexpected T_ELSE". In this case, there's a work-around:

php > if(conditional)
php > {
php {   // ...
php { } else
php > {
php {   // ...
php { }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the additional info !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.