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>";
}
?>
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With