我有下面这段PHP的,这是给我一个:“意外T_VARIABLE”(假定与HEREDOC)
Parse error: syntax error, unexpected '$author' (T_VARIABLE) in /var/www/html/blog/index.php on line 77
<?php
class Post
{
//Define placeholders
public $title = 'Post Title';
public $timestamp = 'TIMESTAMP';
public $author = 'Author';
public $author_url = '/user/'. $author;
$post_boilerplate = <<<EOF
<div class="blog-post">
<h2 class="blog-post-title"> $this->title </h2>
<p class="blog-post-meta">$this->timestamp by <a href="$this->author_url">$this->author</a></p>
<p>Blah, blah, blah...</p>
</div><!-- /.blog-post -->
EOF;
public function print_post() {
echo $this->post_boilerplate;
}
}
$post = new Post();
$post->print_post();
?>
我试着注释掉参考线作为一个快速“修复',但那么错误就会移动。
随着
//public $author_url = '/user/'. $author;
我得到:
Parse error: syntax error, unexpected '$post_boilerplate' (T_VARIABLE), expecting function (T_FUNCTION) in /var/www/html/blog/index.php on line 79
注释掉HEREDOC过“帮助”,在包含页面获取生成,显然尽管有与失踪的变量声明错误,但显然这并不是真正的解决方案。
任何人都可以阐明什么是错的?
Heredoc文本不应缩进。 –
从我读过的东西,sych作为http://stackoverflow.com/questions/4068556/php-using-proper-indentation-with-heredocs我得到的想法,它只是结束分隔符必须存在于一行本身。无论如何,删除缩进并没有解决问题:我仍然得到我引用的第一个错误。 –