*
+------------------------------------------------ ----------------------------------+
| = This article is read by Haohappy<
| = Notes from the Chapter Classes and Objects
| = Translation + personal experience
| = To avoid possible unnecessary trouble, please do not reprint, thank you
| = Welcome criticisms and corrections, and hope to make progress together with all PHP enthusiasts!
| = PHP5 Research Center: http://blog.csdn.net/haohappy2004
+---------- -------------------------------------------------- ------------------+
*/
Section 9--Binding
In addition to restricting access, the access method also determines which method will be subclassed The call or which property will be accessed by the subclass. The relationship between the function call and the function itself, and the relationship between member access and variable memory address, is called binding.
There are two main binding methods in computer languages - static Binding and dynamic binding. Static binding occurs between data structures and data structures, before program execution. Static binding occurs at compile time, so it cannot use any runtime information. It targets function calls and the body of the function, or Variables and blocks in memory. Because PHP is a dynamic language, it does not use static binding. But it can simulate static binding.
Dynamic binding is for access requests generated during runtime, and is only used during runtime available information. In object-oriented code, dynamic binding means that the decision about which method is called or which property is accessed will be based on the class itself and not based on the access scope.
Public and protected members behave similarly to PHP In previous versions of the function, dynamic binding was used. This meant that if a method accessed a class member that was overridden in a subclass, and was an instance of the subclass, the subclass member would be accessed (while Not accessing members in the parent class).
Look at Example 6.10. This code outputs "Hey! I am Son." Because when PHP calls getSalutation, it is an instance of Son, which overwrites the salutation in Father. . If the salutation is public, PHP will produce the same result. Overriding a method operates similarly. In Son, the call to identify is bound to that method.
Even in subclasses the access method is weakened from protected becomes public, dynamic binding will still occur. According to the principle of using access methods, it is impossible to enhance access restrictions on class members. Therefore, changing the access method from public to protected is impossible.
Listing 6.10 Dynamic binding Dynamic Binding
http: //www.bkjia.com/PHPjc/316941.html