<?php
class MyClass {
public static $str = "Hello World!";
public static function hello() {
echo MyClass::$str;
}
}
echo MyClass::$str;
echo "<br>";
echo MyClass::hello();
?>
Why use static keywords in PHP?
Static keywords in PHP are used to keep a copy of a function or a class' static variables from one call to another. This allows a function to maintain its state even after it has been called. Static keywords are also used to create static methods, which are methods that are accessible without creating an instance of a class.
Related Posts
Search
Subscribe for Updates
Categories
Facebook Post