Scope resolution operator

From Wikipedia, the free encyclopedia
  (Redirected from Paamayim Nekudotayim)
Jump to: navigation, search

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. The specific uses vary across different programming languages with the notions of scoping. In many languages the scope resolution operator is written ::.

Contents

C++ [edit]

  class A
  {         //
    static int i;  //scope of A
  }         //
  A::i = 4; //scope operator refers to the integer i declared under the namespace A

PHP [edit]

In PHP, the scope resolution operator is also called Paamayim Nekudotayim (Hebrew: פעמיים נקודתיים‎, pronounced [paʔaˈmajim nəkudoˈtajim]), which means "twice colon" or "double dot twice" 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 5, as in this sample error message:

$ php -r ::
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

A 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:

$ php -r 'define("foo", "bar"); if (empty(foo)) echo "empty";'
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM

As of PHP 5.4, error messages concerning the scope resolution operator still include this name, but have clarified its meaning somewhat:

$ php -r ::
Parse error:  syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)

Ruby [edit]

In Ruby, scope resolution can be specified using namespaces (such as classes or modules).

  module Example
    Version = 1.0
 
    class << self # We are accessing the Module's singleton class
      def hello(who = "World")
         "hello #{who}"
      end
    end
  end #/Example
 
  Example::hello # => "hello World"
  Example.hello "hacker" # => "hello hacker"
 
  Example::Version # => 1.0
  Example.Version # NoMethodError
 
  # This illustrates the difference between the message (.) operator and the scope operator in Ruby (::)
  # We can use both ::hello and .hello, because hello is a part of Example's scope and because Example
  # responds to the message hello.
  #
  # We can't do the same with ::Version and .Version, because Version is within the scope of Example, but
  # Example can't respond to the message Version, since there is no method to respond with.

References [edit]

  1. ^ "Scope Resolution Operator". PHP 5 Manual. Retrieved 2007-08-09. 


External links [edit]