<?php
/**
*PHP面向对象:克隆对象1
*/
class Person{
private $name;
private $sex;
private $age;
function __construct($name="",$sex="",$age=1){
$this->name=$name;
$this->sex=$sex;
$this->age=$age;
}
function say(){
echo "我是".$this->name.",性别".$this->sex.",年龄".$this->age."<br/>";
}
}
$p1=new Person("不高兴","男",12);
$p2=clone $p1; // 克隆对象p1(不是复制对象,是复制一个该对象的引用。)
$p1->say();
$p2->say();
/**
*PHP面向对象:克隆对象1
*/
class Person{
private $name;
private $sex;
private $age;
function __construct($name="",$sex="",$age=1){
$this->name=$name;
$this->sex=$sex;
$this->age=$age;
}
function say(){
echo "我是".$this->name.",性别".$this->sex.",年龄".$this->age."<br/>";
}
}
$p1=new Person("不高兴","男",12);
$p2=clone $p1; // 克隆对象p1(不是复制对象,是复制一个该对象的引用。)
$p1->say();
$p2->say();