The application of PHP loading class operation and other magic methods

Source: Internet
Author: User
<?php Load 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 load class//1. All class filenames and class names should be consistent//2. All class files are placed under the same file//3. All class file naming rules are consistent with function __autoload ($cname) {    require_once ("./$ Cname.class.php ");    } $t = new test (); $t->ceshi (). ' <br> '; $s = new Ren (); $s->test ();

Two methods of magic

 class ren{public $name;        Public function say () {echo "Output object method";    }//The method of the output object public function __tostring () {echo "another output method";        echo $s->__tostring ();    Return "another output method";//echo $s; }//method for cloning an object public function __clone () {$this->name = "Riven";//$this represents a clone (cloned object)}} $s = new Ren ();//ech O $s->__tostring ();//output string//$s->say (); $s->name = "small V"; var_dump ($s); $s 1 = clone $s; Var_dump ($s 1);? 
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.