Advanced PHP
June 3, 2026 1 min read

PHP Static Variables and Methods in Classes

HS
HEMANT SINGH
Technical Writer & Educator

Static variable and methods are called class variable and methods, they are not part of an object and unable to access variable and methods using object.

To access static variable and methods use scope resolution operator(::).

class Person{
	public static $name="Aman";
	public static function display(){
		echo "Name:". self::$name ."<hr>";
	}
}
$person= new Person();
echo Person::$name;
Person::display();

Static properties with inheritance

class Account{
	public static $name="Aman";	
}

class User extends Account{
	public static $name="Rama";
	public function show(){
		echo parent::$name;
		echo self::$name;
	}
}

$user = new User();
$user->show();