...

View Full Version : Resolved EOT Heredoc Parse Error



RonnyNishimoto
07-20-2012, 02:57 AM
I get a funny error when the "EOT" or the "$end" is indented.



<?php
echo <<< EOT
HELLO!
EOT;
?>


which I researched to be exactly the same as:



<?php
echo <<< PINEAPPLES
HELLO!
PINEAPPLES;
?>


^ works. But if I indent the $end


<?php
echo <<< PINEAPPLES
HELLO!
PINEAPPLES;
?>


it produces an error?:

Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_END_HEREDOC or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN

This seems really funny to me, does anyone know why it does this? I'm more curious as to learn why it gives me an error than "You just can't." :D
I indent all my code, so if I was territory that is indented 20 times, that would mean I would have to put the $end on the very first indent?

Fou-Lu
07-20-2012, 03:40 AM
You cannot indent the ending delimiter (this is documented as such as well). You must put it on a line of its own, and it must not have any preceding whitespace.

So I'm afraid the answer is "You just can't". Its the way the parsing engine works on the heredoc and nowdoc syntax.

RonnyNishimoto
07-20-2012, 03:55 AM
:O That really, really sucks. If that's the case, it's pretty much worthless. Thanks again Fou!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum