PHP eval and heredoc do not play well

Possible duplicate:
heredoc with eval code execution

So, I have a function.php function:

eval("\$content = <<<TEMPLATE\n asdf \nTEMPLATE;"); 

And I get the error message:

 Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_END_HEREDOC or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /var/www/function.php(10) : eval()'d code on line 5 

I can’t understand what the problem is. Obviously the heredoc syntax ending, heredoc just don't like playing well with eval?

+4
source share
1 answer

The HEREDOC syntax ends with a delimiter defined at the beginning, followed by a semicolon, followed by a new line . You do not have a new line, so it is not recognized as the end of a HEREDOC. Add extra \n after TEMPLATE; and it should work fine.

+6
source

Source: https://habr.com/ru/post/1441360/


All Articles