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