Advertisement
Yousuf1791

Book-page-101

May 27th, 2022
931
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class User{
  4.     private $login_id = "";
  5.     private $active_status = "";
  6.  
  7.     public function __construct($id, $status){
  8.         $this->login_id = $id;
  9.         $this->active_status = $status;
  10.     }
  11.  
  12.     public function steLoginId($id){
  13.         $this->login_id = $id;
  14.     }
  15.  
  16.     public function setStatus($status){
  17.         $this->active_status = $status;
  18.     }
  19.  
  20.     public function getLoginId(){
  21.         return $this->login_id;
  22.     }
  23.  
  24.     public function getActiveStatus(){
  25.         return $this->active_status;
  26.     }
  27.  
  28.     public function showUserInfo(){
  29.         echo "Login Id : ". $this->login_id ."<br>";
  30.         echo "Active Status : ". $this->active_status ."<br>";
  31.     }
  32. }
  33.  
  34. class Employee{
  35.     private $user = null;
  36.     private $name = "";
  37.  
  38.     public function __construct($name, User $user){
  39.         $this->name = $name;
  40.         $this->user = $user;
  41.     }
  42.  
  43.     public function __clone(){
  44.         $this->user = clone $this->user;
  45.     }
  46.  
  47.     public function setName($name){
  48.         $this->name = $name;
  49.     }
  50.  
  51.     public function getUser(){
  52.         return $this->user;
  53.     }
  54.  
  55.     public function showEmployeeInfo(){
  56.         echo "<br>Employee Name : ". $this->name ."<br>";
  57.         echo "Login Status : <br>";
  58.         $this->user->showUserInfo();
  59.     }
  60. }
  61.  
  62. $user = new User("yousuf@tappware.com", "1");
  63. $e1 = new Employee("yousuf", $user);
  64.  
  65. // $e2 = $e1;
  66.  
  67. // $e2->setName("Emran");
  68. // $e2->getUser()->steLoginId("emran@dataware.com");
  69. // //
  70. // $e1->showEmployeeInfo();
  71. // $e2->showEmployeeInfo();
  72.  
  73. $e2 = clone $e1;
  74.  
  75. $e2->setName("Emran");
  76. $e2->getUser()->steLoginId("emran@dataware.com");
  77. //
  78. $e1->showEmployeeInfo();
  79. $e2->showEmployeeInfo();
  80.  
  81. ?>
Advertisement
RAW Paste Data Copied
Advertisement