" line but I can't find anything wrong with it...." /> " line but I can't find anything wrong with it...." /> " line but I can't find anything wrong with it...."/>

Heredoc statement showing syntax error

39 views Asked by At

Why am I getting a "unexpected end of file" syntax error? The error appears to be after the closing "?>" line but I can't find anything wrong with it.

<?php

require_once("classPage.php");

$page = new Page();

print $page->getTop();

print <<<EOF

<div id="mainContent">

<p>This is where content would go, should there be any.</p>

</div> <!-- end main content -->

EOF; // no space at start of this line

print $page->getBottom();

?>
<---- Error is here.
2

There are 2 answers

0
Deep Kakkar On

You probably have spaces after the terminator in your code examples, e.g.

[space]EOD;[space]

Also check the space before EOD;. i.e. you have to place your ending heredoc at the beginning of line.

0
viral On

Your code should be something like this, note that comment in code.

<?php

    require_once("classPage.php");

    $page = new Page();

    print $page->getTop();

    print <<<EOF

<div id="mainContent">

<p>This is where content would go, should there be any.</p>

</div> <!-- end main content -->

EOF; // no space at start of this line

    print $page->getBottom();

?>