In computer programming, scope is an enclosing context where values and expressions are associated. The scope resolution operator helps to identify and specify the context to which an identifier refers, particularly by specifying a namespace or class. The specific uses vary across different programming languages with the notions of scoping. In many languages, the scope resolution operator is written ::
.
In some languages, notably those influenced by Modula-3 (including Python and Go), modules are objects, and scope resolution within modules is a special case of usual object member access, so the usual method operator .
is used for scope resolution. Other languages, notably C++ and Ruby, feature both scope resolution and method access, which interact in various ways; see examples below.
namespace B // namespace B
int A::i = 4; // scope operator refers to the integer i declared in the class Aint x = B::c; // scope operator refers to the integer c declared in the namespace B
In PHP, the scope resolution operator is also called Paamayim Nekudotayim (Hebrew: פעמיים נקודותיים, pronounced as /he/, the second word a colloquial corruption of נקודתיים, pronounced as /he/), which means “double colon” in Hebrew.
The name "Paamayim Nekudotayim" was introduced in the Israeli-developed[1] Zend Engine 0.5 used in PHP 3. Although it has been confusing to many developers who do not speak Hebrew, it is still being used in PHP 7, as in this sample error message:
$ php -r ::Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIMA similar error can also occur where no scope resolution operator is present. For example, attempting to check whether a constant is empty triggers this error:
In Ruby, scope resolution can be specified using the module keyword.
class << self # We are accessing the module's singleton class def hello(who = "world") "Hello #" end endend #/Example
Example::hello # => "Hello world"Example.hello "hacker" # => "Hello hacker"
Example::Version # => 1.0Example.Version # NoMethodError
Scope is also affected by sigils which preface variable names:
$
" - global variable@
" - instance variable of [[this (computer programming)|self]]
@@
" - class variable