意外的T_VARIABLE,预期为T_FUNCTION [英] unexpected T_VARIABLE, expecting T_FUNCTION
问题描述
我希望这是一个我忽略的基本语法错误,但我无法弄清楚.
I am expecting this to be a basic syntax error I overlooked, but I can't figure it out.
在PHP脚本中,我不断收到以下错误.
In a PHP script, I keep getting the following error.
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in [path]/scripts/users/database_connection.php on line 4
当用include_once()
调用我连接数据库的脚本时,会发生这种情况.我将脚本剥离为最基本的代码(保留了其他代码所需的内容),但它仍在调用此错误.
This occurs when my script to connect to the database is called with an include_once()
. I stripped my script down to the most basic code (leaving in what is required by other code), and it still is calling this error.
<?php
class UserDatabaseConnection
{
$connection = sqlite_open("[path]/data/users.sqlite", 0666);
public function lookupUser($username)
{
// rest of my code...
}
}
$udb = new UserDatabaseConnection;
?>
我为此苦了一段时间,只是想知道是否还有其他人可以发现我出了问题的地方.
I have struggled with this for a while, and just wondered if anyone else could spot somewhere I went wrong.
推荐答案
您不能放
$connection = sqlite_open("[path]/data/users.sqlite", 0666);
在班级建设之外.您必须将该行放置在函数或构造函数中,但不能将其放置在现在的位置.
outside the class construction. You have to put that line inside a function or the constructor but you can not place it where you have now.
这篇关于意外的T_VARIABLE,预期为T_FUNCTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!