PHP-based loading operations and other two magic methods of the application instance, magic application instance

Source: Internet
Author: User

PHP-based loading operations and other two magic methods of the application instance, magic application instance

The instance is as follows:

<? Php loading class // include (". /Ren. class. php "); // include ". /Ren. class. php "; include_once (". /Ren. class. php "); include_once (". /Ren. class. php "); $ f = new Ren (); $ f-> test (); require (". /Ren. class. php "); require_once (". /Ren. class. php "); require_once ". /Ren. class. php "; $ f = new Ren (); $ f-> test (); automatically loaded class // 1. all class file names and class names must be consistent // 2. put all class files under the same file // 3. all class file naming rules are consistent function _ autoload ($ cname) {require_once (". /$ cname. class. php ");} $ t = new t Est (); $ t-> ceshi (). '<br>'; $ s = new Ren (); $ s-> test (); Two magic methods: class Ren {public $ name; public function say () {echo "method of output object";} // method of output object public function _ tostring () {echo "another method of output "; // echo $ s->__ tostring (); return "Another output method"; // echo $ s ;} // Method for object cloning public function _ clone () {$ this-> name = "Riven"; // $ this indicates a duplicate (cloned object )}} $ s = new Ren (); // echo $ s->__ tostring (); // output string // $ s-> say (); $ s-> name = "Small V"; var_dump ($ s ); $ S1 = clone $ s; var_dump ($ s1);?>

The above PHP-based loading operations and the application examples of the other two magic methods are all the content shared by xiaobian. I hope you can give me a reference, we also hope that you can support the customer's home.

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.