PHP Basic Tutorial
MySQL Connection
PHP Advanced
A static property:
static
keyword:ClassName::$propertyName
or self::$propertyName
from within the class.<?php class ClassName { public static $staticProp = "W3Schools"; } ?>
To access a static property use the class name, double colon (::), and the property name:
ClassName::$staticProp;
Let's look at an example:
Try it yourself
public static $name = "PHP";
Declares a static property called $name
that belongs to the class MyClass
.
MyClass::$name
Outside the class, you use the class name with ::
to access static properties or methods.
static
.A static property can be accessed from a method in the same class using the self
keyword and double colon (::):
Try it yourself
public static $name = "PHP";
Declares a static property called $name
that belongs to the class MyClass
.
self::$name
Inside the class, you use self::
to refer to static members.
MyClass::$name
Outside the class, you use the class name with ::
to access static properties or methods.
To call a static property from a parent class using the parent
keyword inside the child class.
Try it yourself