Cory House
Cory House

Reputation: 15045

How do I call static variable in a separate class in PHP?

How can I access a static variable in a separate class in PHP? Is the scope resolution operator the wrong tool for the job? Example:

class DB {
  static $conn = 'Connection';
}



class User {
  function __construct() {
    DB::conn; //throws "Undefined class constant 'conn' error.
  }
}

Upvotes: 1

Views: 448

Answers (1)

dirtside
dirtside

Reputation: 8270

DB::$conn

You need the $ before the variable name if it's a property.

Upvotes: 9

Related Questions