<?php class test{ protected $a=1; private $b=2; public function __clone(){ echo "有人要克隆我<br/>"; } public function __call($name,$arg){ echo "有人要调用不存在或不可见的方法名",$name,",第一个参数是$arg[0]<br/>"; } public function __set($k,$v){ echo "有人要设置不存在或不可见的属性",$k,"的值为",$v,"<br/>"; } public function __get($k){ echo "有人要获取不存在或不可见的属性",$k; } }
$test1=new test();
$test3=$test1;//此时$test3和$test1是同一个对象,即都指向同一个对象
$test2=clone $test1;//克隆后$test1和$test2是2个不同的对象,虽然存储的值相同
$test1->abc(1,2,3);
$test1->a=3;
$test1->b;