The 11th section--Heavy Duty--classesandobjectsinphp511_php Tutorial

Source: Internet
Author: User
Tags access properties php class
| = This is haohappy read < > | = Notes in Classes and objects Chapter | = Translation-based + personal experience | = Please do not reprint in order to avoid the unnecessary trouble that may occur, thank you | = Welcome criticism, hope and all the PHP enthusiasts to progress together! +-------------------------------------------------------------------------------+ */11th-Heavy Duty PHP4 already has overloaded syntax to build mappings to the external object model, just like Java and COM. PHP5 brings a powerful object-oriented overload that allows programmers to create custom behaviors to access properties and invoke methods. Overloading can be done through __get, __set, and __call several special methods. PHP will call these methods when the Zend engine tries to access a member and does not find it. In example 6.14, __get and __set Replace all access to an array of attribute variables. If necessary, you can implement any type of filter you want. For example, a script can prohibit setting a property value, starting with a certain prefix or containing a certain type of value. The __call method shows you how to invoke an undefined method. When you call an undefined method, the method name and the parameter received by the method are passed to the __call method, and the value of the PHP pass __call is returned to the undefined method. Listing 6.14 User-level Overloading properties[$property _name]) {return ($this->properties[$property _name]);} else {return (NULL);}} function __set ($property _name, $value) {$this->properties[$property _name] = $value;} function __call ($function _ Name, $args) {print ("invoking $function _name ()

n "); Print ("Arguments:"); Print_r ($args); return (TRUE); }} $o = new Overloader (); Invoke __set () assigns a value to a non-existent property variable, activates __set () $o->dynaprop = "Dynamic Content"; Invoke __get () activates __get () print ($o->dynaprop. "
n "); Invoke __call () activates __call () $o->dynamethod ("Leon", "Zeev");?>

http://www.bkjia.com/PHPjc/532154.html www.bkjia.com true http://www.bkjia.com/PHPjc/532154.html techarticle | = Note for Haohappy read > | = Classes and objects in the Chapter | = translation + personal Experience | = To avoid unnecessary inconvenience that may occur please do not reprint, thank you | = Welcome to criticize ...

  • Related Article

    Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.