Quick Guide To PHP Static Properties
The purpose of this article is to introduce the concept of PHP static properties, including how you could declare them and use them in your code.
We will also discuss some useful use cases for static properties, as well as some best practices.
PHP static property is a property shared by all instances of the class.
A static property, in contrast to a regular property, belongs to the class itself, and does not belong to any specific instance of the class. It means that any changes that are made to any static property of one object will have an effect on all the other objects that share the same property.
PHP Static Properties
PHP static properties are properties that belong to a class in general and are not specific to any instance of that class in particular.
PHP static properties are class-level variables that are shared by all instances of a class.
They are declared using the static keyword and can be accessed using the scope resolution operator :: .
Static properties are defined within the class definition, but outside of any methods. They can be initialized with a default value or left uninitialized.
Syntax
<?php class ClassName { public static $staticProp = "mrexamples"; } ?>
Syntax
ClassName::staticProp;
As an example, let’s take a look at the following:
Example: 
Example Explanation
Here, we declare a static property: $name.
Then, we echo the value of the static property by using the class name, double colon (::), and the property name (without creating a class first).
We define a class called a Website with a single static property called $name.
The $name property is defined as “mrexamples.com“.
To access a static property, we use the scope resolution operator (::) followed by the name of the class and the name of the static property. In this case, we access the $name property of the Website class using the following syntax:
Website::$name
The echo statement then outputs the value of the $name property, which is “mrexamples.com”.
There are static methods as well as non-static methods that can be found in a class.
By using the self keyword, as well as the double colon (::), you can gain access to a static property from another method in the same class:
Example: 
Example: 
Example Explanation
Above code defines a class Website with a static property $name set to the value “mrexamples.com” which contains an HTML line break tag. It also defines a child class Printing that extends Website.
The Printing class has a method printingStaticStr() which returns the value of the $name property using the parent::$name syntax. This method can be used to access the static property of the parent class Website.
In the next section, the code prints the value of the $name property of the Printing class using Printing::$name. This will output “mrexamples.com” since the $name property is inherited from the parent class Website.
Finally, the code creates an object $printing of the Printing class using $printing = new Printing(). This line of code creates a new object of the Printing class.
The code then calls the printingStaticStr() method on the $printing object using $printing->printingStaticStr(). This method returns the value of the $name property of the parent class Website using the parent::$name syntax. Since the value of the $name property contains an HTML line break tag, the output will contain a line break between “mrexamples.com” and any subsequent output.
PHP static properties can also be used to store data that is shared across multiple instances of a class, or to keep track of global state within an application.