PHP Object-Oriented supplement

Source: Internet
Author: User

Object-Oriented supplement

Methods of __tostring

Class ren{public    $name;    Public Function __tostring () {        return ' This is human, there is a member variable name representing the name ';    }} $r = new Ren (); Echo $r;

The ToString method is called automatically.

Methods for cloning objects

Class ren{
Public $name;

Public Function __tostring () {
Return "This is the Ren class, with the member variable name representing the name";
}
When the object is cloned, it is automatically called
Public Function __clone () {
$this->name = "John Doe"; $this Representative Copy
}
}
$r = new Ren ();
$r->name = "Zhang San";
Echo $r; Automatically call the ToString method
Var_dump ($R);

$r 1 = clone $r;
Var_dump ($r 1);

Load class

Include ("./test.class.php");
Include "./test.class.php";
Include_once ("./test.class.php");
Include_once "./test.class.php";

Require ("./test.class.php");
Require "./test.class.php";
Require_once ("./test.class.php");
Require_once "./test.class.php";

Auto Load Class
1. The class name must be consistent with the file name
2. Naming conventions for all classes are consistent
3. All classes must be in the same folder

function __autoload ($cname) {
Require_once "./{$cname}.class.php";
}

$t = new Test ();
$t->ceshi ();
$r = new Ren ();
$r->test ();

PHP Object-Oriented supplement

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.