Open In App

What is Static Keyword in PHP?

In PHP, the static keyword is used to declare class members (properties and methods) that belong to the class itself rather than to instances of the class (objects). Static members are shared across all instances of the class and can be accessed without creating an object of the class.

Syntax:

class MyClass {
public static $count = 0;

public static function incrementCount() {
self::$count++;
}
}

MyClass::incrementCount(); // Call static method
echo MyClass::$count; // Access static property


Static Properties:

Static Methods:

Use Cases:

Article Tags :