Page 1 of 1

Ok, I'm sick of encapsed string error

Posted: Mon Sep 26, 2005 1:24 pm
by pilau
Take a look:

Code: Select all

$JSarray .= "events[". $j + 1 ."]={\n";
Now what's wrong with that?

Posted: Mon Sep 26, 2005 1:37 pm
by Nathaniel
Try:

Code: Select all

$JSarray .= 'events['. ++$j .']={' . "\n";
I think it may not like the the "{\n"...

Posted: Mon Sep 26, 2005 1:50 pm
by feyd
It has to do with the +. Operator precedence dictates that plus, minus and dot operators are processed from left to right within a given statement. Here's an illustration of what's happening

Code: Select all

[feyd@home]>php -r "$j = 2; echo 'foo'.$j+1.'bar';"
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in Command line code on line 1

[feyd@home]>php -r "$j = 2; echo 'foo'.$j;//+1.'bar';"
foo2
[feyd@home]>php -r "$j = 2; echo 'foo'.$j+1;//.'bar';"
1
[feyd@home]>php -r "$j = 2; echo 'foo'.($j+1).'bar';"
foo3bar

Posted: Mon Sep 26, 2005 1:55 pm
by pilau
Ok, so it's like math, in general. "Don't forget that braces, are like a concrete wall!" - my math teacher always said.