Searching...
Monday 15 October 2012

PHP : Object Cloning

11:02 pm

Object Cloning 

Object Cloning :

                         Object cloning is the process of creating a copy of an object with fully replicated properties. An object copy is created by using “clone” keyword which calls the objects. __clone() methid. An object __clone() method cannot be called directly.
    $copy-object = clone object;

Object Cloning Example :


<?php
class A
{
    public $x=11;
  }
?>
<?php
$o1 = new A();
$o2 = clone $o1;
echo $o1->x."--".$o2->x."<br>";
$o2->x=22;
echo $o1->x."--".$o2->x;
?>   
OutPut:
11-11
11--22
  

Object Cloning, php object cloning, cloning, object cloning php.    

0 comments:

Post a Comment