0

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.

3
  • Problem's not the heredoc. It's the var. Commented Feb 10, 2011 at 19:54
  • O_o "var"... this brings up old memories to my head. Why are you using this keyword? Why not just remove it? Commented Feb 10, 2011 at 19:56
  • var? like in Pascal or JavaScript... not in PHP Commented Feb 10, 2011 at 19:59

4 Answers 4

5

The var keyword on the first line is for declaring variables in classes only. Leave it out.

Sign up to request clarification or add additional context in comments.

1 Comment

And even there it's just an old leftover from PHP 4.
3

remove the word var.

see http://www.php.net/manual/en/language.variables.basics.php

Comments

1

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.

Comments

0

D'oh. Removing the 'var' keyword fixed it. Thanks for the input guys!

Unfortunately however it didn't solve my actual problem. See here:

$param = array_merge($_REQUEST, $_FILES, $_COOKIE);

$param['example'] = "example";

example();

function example()
{
    global $param;
    echo <<<EOT
        <p>$param['example']</p>
EOT;
    return;
}

This time the complaint is:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ..... on line ...

Again, what is going on here?

3 Comments

Drop the quotes. i.e. write $param[example]. Or write {$param['example']}.
try surrounding the argument with curly braces: {$param['example']}
Thank you as well. I actually prefer that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.