Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Unexpected 'var' (T_VARIABLE)

Tags:

php

For whatever reason, I have a small bit of PHP code that no matter where I put var $blah;, it always gives this error in the logs: PHP Parse error:  syntax error, unexpected 'var' (T_VAR) in /path/to/file.php on line xx

I have no idea why it wouldn't accept this. A class that is included (which creates the $proverbSite variable in another php section) uses plenty of 'var $blah', with no problems. I also realise this is probably just an embarassingly simple mistake.

<?php
        $proverbSite->dbConnect();
        $result = $proverbSite->dbQuery("randProverb");

        if($result != null) {
            $row = $result->fetch_assoc();
            echo $row['proverb'];
            echo "<br>";
        }

?>
like image 842
ZephireNZ Avatar asked Jul 30 '13 00:07

ZephireNZ


People also ask

What is T_variable error in php?

A T_VARIABLE is a Token of type VARIABLE. When the parser processes tokens, it tries to make sense of them, and throws errors if it receives a variable where none is allowed.


2 Answers

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.

like image 89
Lex Avatar answered Oct 08 '22 20:10

Lex


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

like image 20
PHPman Avatar answered Oct 08 '22 19:10

PHPman