3

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?

0

1 Answer 1

6

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 ->.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.