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>";
}
?>
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.
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!
Check the line before xx
because you may have forgotten a ;
and this may cause PHP to interpret it incorrectly
I know that in newer versions of Laravel it works if you leave out the var keyword, for example:
Route::get('/read', function(){
$results = DB::select('select * from posts where id = ?', [1]);
return dump($results);
});