Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

A clone instance of class in php

Sun Oct 26, 2008 11:47 pm

Code:
<?php

   
class Employee {
   
      
private $employeeid;
      
private $tiecolor;

      function
setEmployeeID($employeeid) {
         
$this->employeeid = $employeeid;
      }

      function
getEmployeeID() {
         return
$this->employeeid;
      }

      function
setTiecolor($tiecolor) {
         
$this->tiecolor = $tiecolor;
      }

      function
getTiecolor() {
         return
$this->tiecolor;
      }

      function
__clone() {
         
$this->tiecolor = "blue";
      }

   }

   
$drone1 = new Employee();

   
$drone1->setEmployeeID("1111");
   
   
$drone2 = clone $drone1;

   
$drone2->setEmployeeID("1111");

   echo
"drone1 employeeID: ".$drone1->getEmployeeID()."<br />";
   echo
"drone2 employeeID: ".$drone2->getEmployeeID()."<br />";
   echo
"drone2 tiecolor: ".$drone2->getTiecolor()."<br />";
?>




Post a reply
  Related Posts  to : A clone instance of class in php
 Pass class instance as parameter in php     -  
 Create object instance from class Name by reflection     -  
 when to use clone in java     -  
 clone arrayList elements     -  
 What exact mean by Object, Reference and Instance?     -  
 Define class helper class to check the method existance     -  
 java abstract class,concrete class and interface     -  
 relationship between the Canvas class and the Graphics class     -  
 inner class that is a member of an outer class?     -  
 Define class inside another class C++     -  

Topic Tags

PHP OOP