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