Parse error: syntax error, unexpected T
I am using objects in php. I have an object to connect to database server $con object and $opt (operation) object to send query to database server, till now there is no problem, the problem is that I defined the $con object as static and I defined it in $opt object as it shows in below code
class operations{
public static $con = null;
public function __construct($tableName = null){
// Creating an object of connection
self::$con = new config();
self::$con = self::$con->getConnection();
}
}
So when I want to call the $con object there is no problem
mysql_query($query,$opt::$con) or die (mysql_error());
but on server it appears with this error
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
Your scope resolution is unexpected, that means that you use it in a bad context. When do you use "::"? After self
static
, classname or a string representing the name of a class :
static::PropertyOrMethod;
self::PropertyOrMethod;
CLassName::PropertyOrMethod
$string = "className";
$string::PropertyOrMethod
Instead of that, you use it over ans instance of your class and php does not like it. You should use mysql_query($query,operations::$con) or die (mysql_error());
T_PAAMAYIM_NEKUDOTAYIM is Hebrew, and it refers to PHP's scope resolution operator (“::”). If you get this message, it means PHP sees a class name and expects you to access it with the scope resolution operator.
update:
After seeing the edit to you code you made a mistake in the call. The right syntax is:
mysql_query( $query, operations::$con ) or die (mysql_error());
链接地址: http://www.djcxy.com/p/69430.html
上一篇: 在PHP中使用静态方法访问私有
下一篇: 解析错误:语法错误,意外的T