EOD does not end?

alt text

<?php // Page class class Page { // Declare a class member variable var $page; var $title; var $year; var $copyright; // The Constructor function function Page($title, $year, $copyright){ // Assign values to member variables $this->page = ''; $this->title = $title; $this->year = $year; $this->copyright = $copyright; // Call the addHeader() method $this->addHeader(); } // Generates the top of the page function addHeader(){ $this->page .= <<<EOD <html> <head> <title>$this->title</title> </head> <body> <h1 align="center">$this->title</h1> </body> EOD; } } ?> 
+4
source share
3 answers

EOD; must be at the very beginning of the line. No space or anything else in front of it

Quote from the manual:

Attention
It is very important to note that the line with the closing identifier should not contain other characters, with the possible exception of the semicolon (;). It is especially important that the identifier may not be indented, and there may be no spaces or tabs before or after the semicolon. It is also important to understand that the first character before the closing identifier must be a new line, determined by the local operating system. This is \ n on UNIX systems, including Mac OS X. A closing delimiter (possibly a semicolon) should also be respected along the new line.

If this rule is violated and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue to search for it. If the correct closing identifier is not found before the end of the current file, a parsing error will result in the last line.

+12
source

You should not depart from the heredoc marker, it is not recognized in leading spaces or tabs.

+4
source

It's hard to tell the actual problem, but look at the heredoc docs: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

+1
source

All Articles