Scope Resolution operator in PHP
The scope resolution operator also known as Paamayim Nekudotayim or more commonly known as the double colon is a token that allows access to static, constant, and overridden properties or methods of a class.
It is used to refer to blocks or codes in context to classes, objects, etc. An identifier is used with the scope resolution operator. The most common example of the application of the scope resolution operator in PHP is to access the properties and methods of the class.
The following examples show the usage of the scope resolution operator in various scenarios.
Example 1: This type of definition is used while defining constants within a class.
Example 2: Three special keywords self, parent, and static are used to access properties or methods from inside the class definition.
Example 3: When an extending class overrides its parent’s function, the compiler calls the child class’s version of the method but it is up to the child class to call its parent’s version of the method.
myfunc() of parent class myfunc() of child class