Heredoc error showing Parse error

The code below shows the parsing error:

Parse error: syntax error, unexpected $end, expecting T_VARIABLE 
or T_END_HEREDOC 
or T_DOLLAR_OPEN_CURLY_BRACES 
or T_CURLY_OPEN in D:\xampp\htdocs\project1\conf.php 
on line 10

      

This is my code in conf.php file

$chat_code = 
<<<EOD

<script>alert('Hi')</script>

EOD;

      

+3


source to share


1 answer


From manual :

Warning: It is very important to note that the line with the closing identifier must not contain any characters other than the semicolon (;). This means especially that the identifier cannot be indented, and there cannot be any spaces or tabs before or after the semicolon. It is also important to understand that the first character before closing the identifier must be a newline as defined by the local operating system. This is \ n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.If this rule is violated and the closing identifier is not "clean", it is not considered a closing identifier and PHP will continue looking for it. If the correct closing id is not found before the end of the current file, parsing an error will result in the last line. Heredocs cannot be used to initialize class properties. As of PHP 5.3, this limitation is only valid for heredocs containing variables.



Thus, your heredoc line-closing delimiter must have no leading characters and no further characters other than the newline character.

+3


source







All Articles