HOME

TheInfoList



OR:

In
computer programming Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as anal ...
,
scope Scope or scopes may refer to: People with the surname * Jamie Scope (born 1986), English footballer * John T. Scopes (1900–1970), central figure in the Scopes Trial regarding the teaching of evolution Arts, media, and entertainment * CinemaS ...
is an enclosing context where
values In ethics and social sciences, value denotes the degree of importance of something or action, with the aim of determining which actions are best to do or what way is best to live (normative ethics in ethics), or to describe the significance of dif ...
and
expression Expression may refer to: Linguistics * Expression (linguistics), a word, phrase, or sentence * Fixed expression, a form of words with a specific meaning * Idiom, a type of fixed expression * Metaphorical expression, a particular word, phrase, ...
s are associated. The scope resolution operator helps to identify and specify the context to which an
identifier An identifier is a name that identifies (that is, labels the identity of) either a unique object or a unique ''class'' of objects, where the "object" or class may be an idea, physical countable object (or class thereof), or physical noncountable ...
refers, particularly by specifying a
namespace In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces ...
. The specific uses vary across different
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming l ...
s with the notions of scoping. In many languages, the scope resolution operator is written ::. In some languages, notably those influenced by
Modula-3 Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2 known as Modula-2+. While it has been influential in research circles (influencing the designs of languages such as Java, C#, and Python) it has not ...
(including Python and Go), modules are
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an ai ...
s, 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 A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum (aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapp ...
, feature both scope resolution and method access, which interact in various ways; see examples below.


C++

class A ; namespace B // namespace B int A::i = 4; // scope operator refers to the integer i declared in the class A int x = B::c; // scope operator refers to the integer c declared in the namespace B


PHP

In
PHP PHP is a General-purpose programming language, general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementati ...
, the scope resolution operator is also called Paamayim Nekudotayim ( he, פעמיים נקודותיים, , the second word a colloquial corruption of נקודתיים, ), which means “double colon” in Hebrew. The name "Paamayim Nekudotayim" was introduced in the Israeli-developed 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_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) There are other less obvious ways to trigger the error, for example by attempting to use the following invalid PHP expression: $ php -r static const '$a=1' Parse error: syntax error, unexpected end of file, expecting :: (T_PAAMAYIM_NEKUDOTAYIM)


Ruby

In
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum (aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapp ...
, scope resolution can be specified using the module keyword. module Example Version = 1.0 class << self # We are accessing the module's singleton class def hello(who = "world") "Hello #" 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. Scope is also affected by sigils which preface variable names: * "$" -
global variable In computer programming, a global variable is a variable with global scope, meaning that it is visible (hence accessible) throughout the program, unless shadowed. The set of all global variables is known as the ''global environment'' or ''global ...
* "@" -
instance variable In class-based, object-oriented programming, an instance variable is a variable defined in a class (i.e. a member variable), for which each instantiated object of the class has a separate copy, or instance. An instance variable has similari ...
of
self The self is an individual as the object of that individual’s own reflective consciousness. Since the ''self'' is a reference by a subject to the same subject, this reference is necessarily subjective. The sense of having a self—or ''selfhood ...
* "@@" -
class variable In class-based, object-oriented programming, a class variable is a variable defined in a class of which a single copy exists, regardless of how many instances of the class exist. A class variable is not an instance variable. It is a special ...
* No sigil, lowercase or underscore -
local variable In computer science, a local variable is a variable that is given ''local scope''. A local variable reference in the function or block in which it is declared overrides the same variable name in the larger scope. In programming languages with o ...
or method * No sigil, uppercase -
constant Constant or The Constant may refer to: Mathematics * Constant (mathematics), a non-varying value * Mathematical constant, a special number that arises naturally in mathematics, such as or Other concepts * Control variable or scientific const ...


References

{{Reflist


External links


Bjarne Stroustrup's C++ Glossary
Operators (programming) PHP software Articles with example C++ code Articles with example Ruby code Articles with example PHP code