The text of this article is not in this database — only its details are. Read it on the old site: Constructor and Destructor in PHP
5 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: Constructor and Destructor in PHP
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
Nitin BhardwajPosted Feb 4, 2013, 9:00 AM
Oky Thank u Sharad
Sharad GuptaPosted Feb 4, 2013, 8:12 AM
Hi Nitin , if you want to implement copy constructor in PHP,then you can use clone method to implement copy constructor facility in PHP. <?php class Myclass { static $instances=0; public $instance; function __construct() { $this->instance=++self::$instances; } function __clone() { $this->instance=++self::$instances; } } class Baseclass { public $object1; public $object2; function __clone() { $this->object1=clone $this->object1; } } $obj = new Baseclass(); $obj->object1=new Myclass(); $obj->objec21=new Myclass(); $obj2=clone $obj; echo "<pre>"; print("Orignal object:\n"); print_r($obj); print("clone object:\n"); print_r($obj2); ?>
Nitin BhardwajPosted Feb 4, 2013, 5:43 AM
Hi Sarad, Can we create copy constructor in PHP?
Sharad GuptaPosted Feb 1, 2013, 7:33 AM
thanks Prabhakar
Prabhakar MauryaPosted Feb 1, 2013, 4:44 AM
Nice Explain...