PHP Unexpected 'var' (T_VARIABLE)

Keyword var is only used in classes (in PHP). In the plain scope variables are automatically declared as you mention them. Just erase it, and it should work.


Check the line before xx because you may have forgotten a ; and this may cause PHP to interpret it incorrectly


Without seeing all the sources involved, I'm guessing you're combining JavaScript and PHP.

JavaScript variable declarations begin with 'var' and PHP does not... If PHP were to encounter the code 'var' before a variable, it would give the error message you listed. T_VAR usually indicates PHP is trying to interpret a constant, which would be the case with a JavaScript 'var'.

Now, as for the plugin/library your are using, it may be echoing javascript, but including a PHP variable, ex:

echo "var myJavasScriptVar = '$phpVar'";

In PHP, '$' in a string means that it will be replaced by a variable.

Hope this helps!

Tags:

Php