Properties are just another name for variables, but they reside inside a class. To access the property of a class, we have to create a new instance of the class using the new keyword. We can access static properties directly without instantiating the class.
Let's see an example.
Let's see an example:
<?phpclass Bio {public static $name = "John Doe";}// Accessing property valueecho Bio::$name;?>
From the above code:
Bio
.name
. Notice the syntax of how we created the property.public
keyword so that other classes can access it. static
keyword so it can be a static property.$name
value by accessing the static property.We use the ::
after the Bio
class in echo Bio::$name
, and we do not need to create a new instance of the Bio
class.