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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MrCheese
Forum Newbie
Posts: 2
Joined: Mon Mar 05, 2007 8:03 am

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

Post 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]
Last edited by MrCheese on Mon Mar 05, 2007 8:40 am, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP isn't finding your "EOD" marker. It must be the first thing on the line, literally. No whitespace.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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;
         }
}
?>
MrCheese
Forum Newbie
Posts: 2
Joined: Mon Mar 05, 2007 8:03 am

Post 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. :-)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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:).
Post Reply