Page 1 of 1
[SOLVED]Heredoc giving parse errors...
Posted: Sat Jan 03, 2004 11:33 am
by infolock
Nay, if you are out there, here is a good one for ya. Otherwise, someone else might know the answer to this one.
I've just started trying out heredoc. it works pretty good until you try to tab within it to keep your code straightened up. When I put tabs before my html tags, or the end of my ending of heredoc, i get parse errors every time. i remove the tabs, and it then works fine.
is there something i'm missing here? also, if i replace the tabs with spaces, it works fine, but i really don't want to have to sit and go through every line and add x # of spaces...

Posted: Sat Jan 03, 2004 11:48 am
by onefocus99
Depending on what editor you are using
i.e. notetab.com or Macromedia HomeSite 5
both have: Convert Tabs to spaces or spaces to Tabs
Posted: Sat Jan 03, 2004 1:16 pm
by qads
lol, as soon as i read the title i knew nay's name will be in there somewhere...and its true, wonder why he hast replied yet lol
Posted: Sat Jan 03, 2004 3:28 pm
by DuFF
From
http://www.php.net/types.string
Warning
It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon ( ; ). That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is \r on Macintosh for example.
If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one. If in this case a proper closing identifier is not found then a parse error will result with the line number being at the end of the script.
You can't have any spaces on the last line of the heredoc, I think this is your problem.
Posted: Sat Jan 03, 2004 6:08 pm
by JAM
My bet is a)
onefocus99 version, tabs vs. 4spaced space-indents or b)
DuFF's version, malplaced ending (or beginning).
Code: Select all
//works
$str = <<<EOD
<b>Example of string
EOD;
// does not work
$str = <<<EOD
<b>Example of string
EOD; // space before EOD
// nor
$str = <<<EOD
<b>Example of string EOD;
Posted: Tue Jan 06, 2004 7:18 pm
by infolock
onefocus99 wrote:Depending on what editor you are using
i.e. notetab.com or Macromedia HomeSite 5
both have: Convert Tabs to spaces or spaces to Tabs
nice. it was actually the 4 space issue with Homesite.. at least they offer tab to space heh. only i just don't like having to increase my file size for something that mundane. oh well, i guess i'll have to get used to it til i find a better editor lol..
have tried zend, and most of the others listed on the "what editor do you use", but overall hs has been the best... except for this one small problem with heredoc heh..
thanks again