Search code examples
phpvariablesechophp-5.3heredoc

PHP error when attempting to print variables within an echo using heredoc


When I try to do this:

var $example = "Example";
echo <<<EOT
<p>$example</p>
EOT;

I get this error:

Parse error: syntax error, unexpected T_VAR in ..... on line ...

What is going on here?? To my knowledge this should work.

I'm using PHP 5.3.5.


Solution

  • There is no keyword var in PHP. Not in PHP5 anyway - it's only accepted due to backward compatibility, and is used to define class variables.