php syntax error, unexpected T_OBJECT_OPERATOR

what I did is, I used a static field in my Database class, to store mysqli object. here is the code :

public static $Driver;

public static function Connect()
{
  self::$Driver = new mysqli(self::$Server, self::$DBUsername, self::$DBPassword, self::$DBName);
}

later, in another class, I want to use this static field. I tried this :

if (Database::Driver->errno != 0) return(false); else return(true);

and got this error for that line :

syntax error, unexpected T_OBJECT_OPERATOR ...

can you tell me what I'm doing wrong?

Answers


To access a static property, you need a $ after the ::. The class property $Driver is accessed as though it is a variable in scope of class Database.

 if (Database::$Driver->errno != 0)
 //-----------^^^

Without the $, it would be parsed as a class constant, and constants, which are primitives, cannot have object properties of their own. Hence the unexpected T_OBJECT_OPERATOR, which means an unexpected ->.


Need Your Help

Error installing MVVMCross from nuget into a PCL

visual-studio-2012 nuget mvvmcross portable-class-library

When I try to install MvvmCross into a new PCL I receive an error. The console log is below:

CodeIgniter back button after logout

php html codeigniter session caching

I'm trying to stop/disable the back button functionality of the browser when a user logs out of my CodeIgniter (PHP) app. But, I think the browser is caching the page so it becomes visible despite ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.