Unexpected $end при множественном <<< в условии

Deviorian

Новичок
Unexpected $end при множественном <<< в условии

Почему-то неправильно обрабатывается следующий код:
PHP:
<?
$a = 1;
$b = 1;
if ($a==$b){
$body = <<<EOV
a
EOV;
}else{
$body = <<<EOV
c
EOV;     
}
echo $body;
?>
выдавая ошибку
PHP Parse error: parse error, unexpected $end in test.php on line 14
Причем, если сменить метод присваивания в else на
PHP:
<?
$a = 1;
$b = 1;
if ($a==$b){
$body = <<<EOV
a
EOV;
}else{
$body = 'c';
}
echo $body;
?>
Все будет нормально. В чем может быть ошибка?
 

Deviorian

Новичок
Тьфу-ты, ну-ты! Я то и не заметил, что после EOV; пробелы.
Да и вообще не думал, что это на что-то влияет.
Спасибо большое за помощь!
 

Гравицапа

elbirret elcno
It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is \r on Macintosh for example. Closing delimiter (possibly followed by a semicolon) must be followed by a newline too.
If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one. If in this case a proper closing identifier is not found then a parse error will result with the line number being at the end of the script.
 

Фанат

oncle terrible
Команда форума
Deviorian
heredoc вообще в пхп вещь бессмысленная.
не нужно им пользоваться. тогда и проблем не будет.
 
Сверху