可我浪费着我寒冷的年华

跟着百度学PHP[4]OOP面对对象编程-14-克隆对象__clone()方法

 

$b=clone ($a) #克隆a对象。

<?php 
class Human
{
	private $name;
	private $sex;
	private $age;
	
	function __construct($name,$sex,$age)
	{
		$this->name=$name;
		$this->sex=$sex;
		$this->age=$age;
	}
	function say(){
		echo $this->name."是他的名字。";
	}
}
$a=new Human("张大牛","男",21);
$b=clone($a); #克隆a对象。
$b->say();
 ?>
输出效果如下所示:
张大牛是他的名字。

  

 

posted @ 2016-12-14 21:13  珍惜少年时  阅读(170)  评论(0编辑  收藏  举报
可我浪费着我寒冷的年华