In this article, you will learn about static keyword in PHP. The static keyword in PHP is used to declare properties and methods of a class as static. Static properties and methods can be used without creating an instance of the class.
It is also used inside the function to declare variable to keep the state saved.
examples of the STATIC keyword
Example 1. In this example, we create and use static properties and methods.
<?php
class MyClass {
public static $str = "Hello World!";
public static function hello() {
echo MyClass::$str;
}
}
echo MyClass::$str;
echo "<br>";
echo MyClass::hello();
?>