The scope resolution operator :: (aka in Hebrew as Paamayim Nekudotayim or the double colon) is explicitly used to access static, constant and overridden properties and methods of a class. The class required is defined to the left of the :: operator and the member to the right.
Syntax:
className::memberName ;
<?php class Bike { public $name; public function setName($myName) { $this->name = $myName; } public function greet() { echo "Welcome to the Ducati appreciation club!<br>"; } public function speak() { echo "The latest Ducati road going sports bike is the $this->name.<br><br>"; } } class MotoGP extends Bike { private $prototype; public function setPrototype($myPrototype) { $this->prototype = $myPrototype; } public function greet() { echo "Welcome Ducati MotoGP supporters!<br>"; } public function speak() { echo Bike::greet(); echo $this->greet(); echo "The $this->prototype is the MotoGP prototype racing equivalent of their road bike.<br><br>"; } } Bike::greet(); $panigale = new Bike; echo "The above shows a class method being called without an object instance.<br><br>"; $panigale->setName("Panigale"); $panigale->speak(); $desmodici = new MotoGP; $desmodici->setPrototype("Desmodici"); $desmodici->speak(); MotoGP::greet(); ?>
Save & refresh browser:
Welcome to the Ducati appreciation club! The above shows a class method being called without an object instance.
The latest Ducati road going sports bike is the Panigale.
Welcome to the Ducati appreciation club!
Welcome Ducati MotoGP supporters! |