Name bindingIn programming languages, name binding is the association of entities (data and/or code) with identifiers.[1] An identifier bound to an object is said to reference that object. Machine languages have no built-in notion of identifiers, but name-object bindings as a service and notation for the programmer is implemented by programming languages. Binding is intimately connected with scoping, as scope determines which names bind to which objects – at which locations in the program code (lexically) and in which one of the possible execution paths (temporally). Use of an identifier id in a context that establishes a binding for id is called a binding (or defining) occurrence. In all other occurrences (e.g., in expressions, assignments, and subprogram calls), an identifier stands for what it is bound to; such occurrences are called applied occurrences. Binding time
An example of a static binding is a direct C function call: the function referenced by the identifier cannot change at runtime. An example of dynamic binding is dynamic dispatch, as in a C++ virtual method call. Since the specific type of a polymorphic object is not known before runtime (in general), the executed function is dynamically bound. Take, for example, the following Java code: import java.util.List;
public void foo(List<String> list) {
list.add("bar");
}
Rebinding and mutationRebinding should not be confused with mutation or assignment.
Consider the following Java code: import java.util.LinkedList;
LinkedList<String> list;
list = new LinkedList<String>();
list.add("foo");
list = null;
{
LinkedList<Integer> list = new LinkedList<Integer>();
list.add(Integer(2));
}
The identifier Late staticLate static binding is a variant of binding somewhere between static and dynamic binding. Consider the following PHP example: class A
{
public static $word = "hello";
public static function hello() { print self::$word; }
}
class B extends A
{
public static $word = "bye";
}
B::hello();
In this example, the PHP interpreter binds the keyword Beginning with PHP version 5.3, late static binding is supported.[3] Specifically, if class A
{
public static $word = "hello";
public static function hello() { print static::$word; }
}
class B extends A
{
public static $word = "bye";
}
B::hello();
See also
References
|