<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <?php //多态 //1.必须要发生在继承下2.子类必须对父类的方法进行重写 /** * *///父类 class Ren { public $name; public $age=18; public function Say() { echo $this->name."正在说话"; } function __construct($n) { $this->name =$n; } function __tostring() { echo "这是一个类"; return "成员变量name的值为:".$this->name."<br/>"."成员方法Say()的作用是。。。"; } function __clone() { $this->age=20;//$this找的是副本 } } $ren =new Ren("aa"); $r1 =clone $ren;//克隆对象 echo $r1;//有tostring可以直接输出克隆对象 //var_dump($r1); //var_dump($ren); //eco $ren //子类 /** * */ /*class china extends Ren { public function Say() { echo "你好"; } } //Ren ri=new China(); //r1.Say(); $ren =new china ("hello"); $ren->Say(); */ //将类引入页面 //include("0322class.php");//可以不加括号。在另一个页面写一个类 require_once"0322class.php"; $test =new Test(); //var_dump($test); //自动加载类 function __autoload($classname) { require_once "class_".$classname . '.php';//注意路径一定要写对 } $test = new Test(); var_dump($test); ?> </body> </html>