Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Exercise-1
<?php //Vaidehi Vaghela rollno:34 /* Create class Person properties are Name, Age, Gender, City. another class Patient extends from person properties are blood_pressure, glucose, spo2, weight.*/ class person { public $name="Vaidehi"; public $age="21"; public $gender="Female"; public $city="Rajkot"; } class patient extends person { public $data=array(); public $blood_pressure; public $glucose; public $spo2; public $weight; // __construct initial all properties when obejct create. public function __construct($glucose) { $this->blood_pressure=100; echo "\n Glucose Level:".$this->glucose=$glucose; // echo "<br>"; $this->spo2=99; $this->weight=60; } public function __set($medicine_name,$dose) { /* __set and __get using this we have to set medicine name and dose based on glucose level. (eg. gliclazide, once_in_day)*/ $data['medicine_name']=$medicine_name; $data['dose']=$dose; echo $medicine_name."-".$dose; echo"\n"; } public function __get($medicine_name) { /* __set and __get using this we have to set medicine name and dose based on glucose level. (eg. gliclazide, once_in_day)*/ If(isset($this->data[$medicine_name])) { return $this->data[$medicine_name]; } } public function __call(String $check_medicine,array $dosage) { /* __call if glucose value is high than 200 have to call method check medicine and its dose.*/ if($this->glucose>200) { echo "\n The method called:".$check_medicine; // echo "<br>"; echo "\n The dose has to be changed:"; print_r($dosage); echo "\n"; } /* __call if glucose level is increasing by 300 it should be change medicine and dose using and set dynamic property.*/ if($this->glucose>300) { echo "\n The method called when Glucose level greater than 300:"; // echo "<br>"; echo "\n The dose has to be changed:"; print_r($dosage); echo "\n"; } } public function __invoke() /* display patient all detail using __invoke method use direct object as function. */ { echo "\n blood_pressure:".$this->blood_pressure=100; //echo "<br>"; echo "\n spo2:".$this->spo2=99; // echo "<br>"; echo "\n weight:".$this->weight=60; // echo "<br>"; } /* using clone keyword one patient object to create another same in instance. */ /*__clone using create another object bus change the age and blood pressure value.*/ public function __clone() { echo __METHOD__." \n cloning of the object"; } } $obj=new patient(205); $obj(); //set method called echo"\n"; $obj->medicine_name='gliclazide'; $obj->dose='once_in_day'; //get method called echo"\n"; $obj->medicine_name; //call method called $obj->check_medicine('twice-in-a-day'); //call method called second time $obj->check_medicine('Gibtulio 5mg','once-in-a-day'); //object cloning $obj1=clone $obj; echo"\n";echo "\n";echo "\n"; var_dump('Patient Details:'); var_dump($obj1); //object cloning,changing age and blood pressure $duplicate=clone $obj; var_dump($duplicate); echo "\n";echo "\n";echo "\n"; echo "\n Changed age:".$duplicate->age="55"; echo"\n Changed BP:".$duplicate->blood_pressure="250"; var_dump($duplicate); ?>
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
AAA
PHP - Stack Implementation
First.php
MY SPACE
Aastha
Perhitungan
Haha
Ttrf
Generadores ejemplos en español
PHP: implode with foreach loops
Please log in to post a comment.