Page 1 of 1

Newbie: <<<EOD causing unexpected $end [Solved]

Posted: Mon Mar 05, 2007 8:24 am
by MrCheese
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Gidday guys - a humble newbie with what is most likely a rather humble question here.

Is there anything that causes an <<<EOD call to throw an "unexpected $end" error message in PHP 5.2 apart from missing curly brackets/semicolons? I'm using the following code - as soon as I replace the EOD call with double-quotes it all works fine. Any suggestions most appreciated. 

Many thanks,
                       - Mr Cheese

Code: Select all

<?php 
class testerclass {
	function testerclass()
	 {
		$page =<<<EOD
		Cannot figure out what is wrong
		EOD;
	 }
}
?>
Error: Parse error: parse error, unexpected $end in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\phpoop\phpoop4class.php on line 10

Works fine when changed to:

Code: Select all

<?php 
class testerclass {
	function testerclass()
	 {
		$page = "Cannot figure out what is wrong";
	 }
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Mar 05, 2007 8:31 am
by feyd
PHP isn't finding your "EOD" marker. It must be the first thing on the line, literally. No whitespace.

Posted: Mon Mar 05, 2007 8:33 am
by CoderGoblin
To make it a bit clearer...

Code: Select all

<?php
class testerclass {
        function testerclass()
         {
                $page =<<<EOD
                Cannot figure out what is wrong
EOD;
         }
}
?>

Posted: Mon Mar 05, 2007 8:42 am
by MrCheese
Sincere thanks Feyd & CoderGoblin, most appreciated. I should have figured it was something like that. Apologies about using code instead of php markers - I'll be sure to get it right from here in. :-)

Posted: Mon Mar 05, 2007 3:06 pm
by RobertGonzalez
There are a few gotchas to look for in HEREDOC syntax. If you are going to use it, you should read the manual on its proper usage (and it does talk about the ending syntax and the error message PHP throws when the end is not all the way to the left, on its own line with nothing else on it :wink:).