Class Ren {public $name; public $sex; function __construct ($n, $s) {$this->name = $n; $this->sex = $s; } function __clone () {$this->name = "John Doe";//this represents the Replica object $this->sex = "Lisi";//this represents the original, then discards}} $r = new Re N ("Zhang San", "male"); Clone $r 1 = Clone $r;
Var_dump ($R); Var_dump ($r 1); Reference class, Load class//About root path: Php inside/representing root path: refers to the disk where the file resides such as d;///html inside/Represents the root path: refers to the server folder: www//include//include//include ("/wamp/www/06 07/ren.class.php "); Include "Ren.class.php"; Require "(Ren.class.php"); Require "(Ren.class.php"); Require_once "(Ren.class.php"); Require_once "(Ren.class.php"); "/"; /*//automatically loads class//1. All class file naming requires the same rule//2. The name must have a class name//3. All class files must be in the same folder
Function__autoload ($classname) {require $classname. ". Class.php "; } $r = new Ren (); Echo $r->name; */
PHP reference classes and load classes, cloning