Scope resolution operator
Encyclopedia
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.

C++

The scope resolution operator (::) in C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

 is used to define the already declared member functions (in the header file with the .hpp or the .h extension) of a particular class. In the .cpp file one can define the usual global functions or the member functions of the class. To differentiate between the normal functions and the member functions of the class, one needs to use the scope resolution operator (::) in between the class name and the member function name i.e. ship::foo where ship is a class and foo is a member function of the class ship. The other uses of the resolution operator is to resolve the scope of a variable
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

 when the same identifier
Identifier
An identifier is a name that identifies either a unique object or a unique class of objects, where the "object" or class may be an idea, physical [countable] object , or physical [noncountable] substance...

 is used to represent a global variable, a local variable, and members of one or more class(es). If the resolution operator is placed between the class name and the data member belonging to the class then the data name belonging to the particular class is referenced. If the resolution operator is placed in front of the variable name then the global variable is referenced. When no resolution operator is placed then the local variable is referenced.Denoted as ::

Example

  1. include


// Without this using statement cout below would need to be std::cout
using namespace std;

int n = 12; // A global variable

int main {
int n = 13; // A local variable
cout << ::n << endl; // Print the global variable: 12
cout << n << endl; // Print the local variable: 13
}

anu

PHP

In PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

, the scope resolution operator is also called Paamayim Nekudotayim , which means "twice colon
Colon (punctuation)
The colon is a punctuation mark consisting of two equally sized dots centered on the same vertical line.-Usage:A colon informs the reader that what follows the mark proves, explains, or lists elements of what preceded the mark....

" or "double colon" in Hebrew
Hebrew language
Hebrew is a Semitic language of the Afroasiatic language family. Culturally, is it considered by Jews and other religious groups as the language of the Jewish people, though other Jewish languages had originated among diaspora Jews, and the Hebrew language is also used by non-Jewish groups, such...

.

The name was introduced in the Israeli-developed Zend Engine
Zend engine
The Zend Engine is an open source scripting engine , commonly known for the important role it plays in the web automation language PHP. It was originally developed by Andi Gutmans and Zeev Suraski while they were students at the Technion - Israel Institute of Technology. They later founded a...

0.5 used in PHP 3. Although it has been confusing to many developers who don't 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
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK