我有下面這段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我得到的想法,它只是結束分隔符必須存在於一行本身。無論如何,刪除縮進並沒有解決問題:我仍然得到我引用的第一個錯誤。 –