search for in the  
<VisibilityStatic Keyword>
Last updated: Thu, 19 May 2005

Scope Resolution Operator (::)

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden members or methods of a class.

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

Paamayim Nekudotayim would, at first, seem like a strange choice for naming a double-colon. However, while writing the Zend Engine 0.5 (which powers PHP 3), that's what the Zend team decided to call it. It actually does mean double-colon - in Hebrew!

Example 19-10. :: from outside the 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 19-11. :: 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's up to the extended class on whether or not the parent's method is called. This also applies to Constructors and Destructors, Overloading, and Magic method definitions.

Example 19-12. 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();
?>


User Contributed Notes
Scope Resolution Operator (::)
HuugjeWeg
29-Apr-2005 07:58
In response to ian at [first name]henderson dot org:

You are not allowed to redefine static methods, see
http://www.php.net/manual/en/language.oop5.static.php

And in response to thenewparadigm at hotmail dot com: the behaviour you describe seems appropriate for *classes* with static variables, see "Using static variables" on http://nl2.php.net/static
thenewparadigm at hotmail dot com
05-Mar-2005 11:43
There is also a quirk with using the scope resolution operator on static class variables.  Below is an example using a highly modified version of Ian's code:

<?php

class ExampleSuperclass
{
   static
$className;

   static function
showClassName() {
     echo
self::$className . "\n";
   }
}

class
ExampleSubclassOne extends ExampleSuperclass
{
   static function
setClassName()
   {
      
self::$className = "subclassOne";
   }
}

class
ExampleSubclassTwo extends ExampleSuperClass
{
   static function
setClassName()
   {
    
self::$className = "subclassTwo";
   }
}

// setting variables for each class
ExampleSubclassOne::setClassName();
ExampleSubclassTwo::setClassName();

ExampleSubclassOne::showClassName();  // output is "subclassTwo"!

// more output:

echo ExampleSubclassOne::$className . "\n"; // output is "subclassTwo"!
echo ExampleSubclassTwo::$className . "\n"; // output is "subclassTwo"
echo ExampleSuperclass::$className . "\n"; // output is "subclassTwo"!

?>

appearantly, any static variables defined in a superclass are directly referenced in subclasses,
and all changes are visible throughout the class heirarchy.  care must be taken when using static
class variables.
ian at [first name]henderson dot org
01-Feb-2005 12:43
Please note that methods called by the scope resolution operator which are defined by a superclass of the first operand are called in the scope of the SUPERCLASS.  For example,

<?php

class ExampleSuperclass
{
   static function
classType()
   {
       return
"superclass";
   }

   static function
doSomething()
   {
       echo
"doing something with " . self::classType();
   }
}

class
ExampleClass extends ExampleSuperclass
{
   static function
classType()
   {
       return
"subclass";
   }
}

ExampleClass::doSomething();
// output is "doing something with superclass"!

?>

This can be surprising (it surprised me!) when coming from other object-oriented languages, which would output "doing something with subclass" in this case.
a dot naumovic at e-motion dot co dot yu
19-Oct-2004 05:42
One additional note about Pa'ama'im Nekudota'im: a suffix ayim is for dual, so the Hebrew language has singular, plural and dual. It's a perfect way to express existence of two  entities of something.
seec77 at zahav dot net dot il
13-Oct-2004 05:01
Just a little fun note about the term "Pa'ama'im Nekudota'im". As a person who originated, and still lives in Israel (land of the Hebrew language), I wanted to explain to everyone what "Pa'ama'im Nekudota'im" means.

"Nekudota'im", is the Hebrew term for a colon.
"Nekudota'im" is a combination of two words... "Neukda", which means "dot"... and "Shta'im" (female form of "Shna'im"), which means "two". Thus, "Nekudota'im" means two dots, and that's why in Hebrew it is used for the colon sign.

"Pa'ama'im", is also a combination of two words. "Pa'am", which means "a time", and again, the postfix originating from "Shtai'm". So "Pa'ama'im" means "two times", or "twice".

We can conclude this, by saying that the expression "Pa'ama'im Nekudota'im" means two times a pair of dots, or a pair of colons, which makes the expression totally legable for calling such an operator.
:)

<VisibilityStatic Keyword>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT