Section 11th-overloading-Classes and Objects in php5[11]
Source: Internet
Author: User
OBJECT|PHP5 | = This article is for Haohappy read <<core PHP programming>>
| = Notes from the chapter classes and objects
| = translation-oriented + personal experience
| = Please do not reprint to avoid any unnecessary trouble that may occur, thank you
| = Welcome to criticize, hope and all PHP enthusiasts to progress together!
+-------------------------------------------------------------------------------+
*/
Section 11th-Overloading
There is already an overloaded syntax in PHP4 to build mappings to the external object model, just like Java and COM. PHP5 brings a powerful object-oriented overload that allows programmers to establish custom behavior to access properties and invoke methods.
Overloads can be performed by __get, __set, and __call several special methods. PHP calls these methods when the Zend engine attempts to access a member and is not found.
In example 6.14, __get and __set Replace all access to an array of property variables. If necessary, you can implement any type of filter you want. For example, a script can disallow setting property values, starting with a certain prefix or containing a certain type of value.
The __call method shows how you can invoke an undefined method. When you call an undefined method, the method name and the parameters received by the method are passed to the __call method, and PHP passes the __call value back to the undefined method.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service