跟着百度学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();
 ?>
输出效果如下所示:
张大牛是他的名字。

  

原文地址:https://www.cnblogs.com/xishaonian/p/6180912.html