How do I call a 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.
  }
}

      

+1


a source to share


1 answer


DB::$conn

      



You need $ in front of the variable name if it's a property.

+9


a source







All Articles