Webhosting and cheap domain registration services
  

 Home

PHP Manual
PrevChapter 18. Classes and Objects (PHP 5)Next

::

The Paamayim Nekudotayim, or in simpler terms, the double colon. This token provides a way to access static, constant or overridden members or methods of a class.

When referencing these items from outside the class definition, you use name of the class.

Paamayim Nekudotayim would, at first, seem a strange choice for a double-colon. However, at the time of writing of Zend Engine 0.5 (which powered PHP3), that is what Andi and Zeev decided to call it. It actually does mean double-colon - in Hebrew! As PHP has progressed with its development it has just never changed.

Example 18-8. :: from outside class definition

<?php
class MyClass {
  const
CONST_VALUE = 'A constant value';
}
echo
MyClass::CONST_VALUE;
?>

Two special keywords self and parent are used to access members or methods from inside the class definition.

Example 18-9. :: from inside the class definition

<?php
class OtherClass extends MyClass {
  
public static $my_static = 'static var';

  
public static function doubleColon() {
     echo
parent::CONST_VALUE . "\n";
     echo
self::$my_static . "\n";
  }
}

OtherClass::doubleColon();
?>

When an extending class overrides the parents definition of a method, php will not call the parent's method. It is up to the extending class to call the parent method or not, this also applies to Constructors and Destructors, Overloading and Magic method defintions as well.

Example 18-10. Calling a parent's method

<?php
class MyClass {

  
protected function myFunc() {
    echo
"MyClass::myFunc()\n";
  }
}

class
OtherClass extends MyClass {

  
/* Override parent's definition */
  
public function myFunc() {

    
/* But still call the parent function */
    
parent::myFunc();
    echo
"OtherClass::myFunc()\n";
  }
}

$class = new OtherClass();
$class->myFunc();
?>

PrevHomeNext
VisibilityUpStatic Keyword

 

  

 

 

 Network sites:

Domain registration : Domain registration and domain name transfer services
Cheap Domain Registrar : Cheap domains or register domain name from $5.95
 

Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to http://www.php.net/docs.php