The following php code will throw an error:
class Foo{
public $bar = <<<EOF
{$this->foobar}
EOF;
public $foobar = "123";
public function echoBar(){
echo $this->bar;
}
}
It doesn't even have to be in brackets, any attempt at variable substitution throws an error.
Can someone explain why? Putting the heredoc inside a function fixes the error, but I was wondering what causes this.
Version of php shell is Zend Engine v2.3.0.
The answer is here in the official PHP docs:
Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables.