Object-oriented: Output object, clone object, load Class

Source: Internet
Author: User

1.__tostring () Can output objects directly

class ren{    public$name;     function Run ()    {        echo"Run";        }     function __tostring ()    The        {return' name variable represents the person name, and the Run method is a running method'        ;    } $r=new  Ren (); Echo $r;

2. Clone Object __clone ()

classren{ Public $name; functionrun () {EchoRun; }    function__tostring () {return"The name variable represents the person, and the Run method is a running method."; }    //The method of automatically invoking when cloning an object//changing content to a copy    function__clone () {$this->name= "John Doe"//represents the copy of the copied object        }    }$r=NewRen ();$r->name= "Zhang San";Var_dump($r);$r 1=Clone $r;//Cloning cloneVar_dump($r 1);

3. Load Class

class file class name. class.php

How to bring the foreign file to the current page
How classes are loaded
1. Include
Include ("./filename");//write the path in parentheses; do the head and tail of the page
Include "./filename";


2. The request will not cause the program to crash
Require ("./filename");
Require "./filename"


3. Request once
/require_once ("./filename")


4 Automatic Load Class
All class files are placed under the same folder
The naming conventions for all class files are consistent
All class files must have the same name as the class name.

function __autoload ($classname)// execute {    require when creating the object $classname. ". Class.php ";    }    

Object-oriented: Output object, clone object, load class

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.