php引用类和加载类,克隆
class Ren { public $name; public $sex; function __construct($n,$s) { $this->name = $n; $this->sex = $s; } function __clone() { $this->name = "李四";//this代表的是副本对象 $this->sex = "lisi";//this代表原本,后来放弃 } } $r = new Ren("张三","男"); //克隆 $r1 = clone $r;
var_dump($r); var_dump($r1); //引用类,加载类 //关于根路径:php里面/代表根路径:指该文件所在的磁盘比如D;/ //html里面/代表根路径:指服务器文件夹:www //include //include //include("/wamp/www/0607/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"); "/"; /*//自动加载类 //1.所有的类文件命名要求使用同一规则 //2.文件名里面必须有类名 //3.所有类文件必须在同一个文件夹下
function__autoload($classname) { require $classname.".class.php"; } $r = new Ren(); echo $r->name; */