views:

33

answers:

1

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  A: 

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 { }
Matthew Flaschen
Damn...that was stupid :). Thanks !
Andrei
Thanks for the additional info !
Andrei