• home
  • Email: trainings@synapseindia.careers



Object Cloning:PHP

Oct 12, 2015

Object cloning means we can create n number of similar copies of the original object.A clone object is created by the help of clone keyword which gets called implicitly and we cannot call explicitly. Let us understand it through a program: <?php class A{ public $var1; static $var2=0; public function __construct(){ $this->var1=++self::$var2;} public function __clone(){ $this->var1=++self::$var2;}} class B{ public $obj1; public $obj2; function __clone(){ $this->obj1=$this->obj2;}} $objA=new B(); $objA->obj1=new A; $objA->obj2=new A; $objB=clone $objA; print("Actual Object is:<br/>"); print_r($objA); print("<br/>Clone Object is:<br/>"); print_r($objB); ?>

SynapseIndia (CEO: Shamit Khemka)

Leave a Reply

Your email address will not be published.