Skip to content
Snippets Groups Projects
Commit 924807d5 authored by Raghav's avatar Raghav
Browse files

Testing with private method and properties to acces their values to test.php

parent cd05afac
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
class Mic
{
public $brand;
public $color;
private $color; //Can access within this class
public $usb_port;
public $model;
public $light;
......@@ -25,7 +25,29 @@ class Mic
return $this-> model;
}
// To print the $model as output:
public function getModel(){
print($this-> model);
}
// To set value to $color with private method
private function setColor($color){
$this -> color = $color;
}
// To display the value with private method
private function getColor(){
return $this -> color;
}
// Accessing private method with public method to get value from test.php
public function setColorProxy($color){
$this -> setColor($color);
}
// Getting values from private method -> private propertiy: to display value to test.php
public function getColorProxy(){
return $this -> getColor();
}
}
......@@ -32,12 +32,20 @@
$mic1 -> light = "RGB";
$mic1 -> setLight("yellow");
// Inserting the string to setModel()
$mic1 -> setModel("toyata innova");
// Displaying the string
$mic1-> getModel();
printf("mic1 = %s\n", $mic1 -> brand);
printf("mic2 = %s", $mic2 -> brand);
printf("mic2 = %s\n", $mic2 -> brand);
// Inserting value to the private property through public method
$mic1 -> setColorProxy("Red");
print("From private color: ". $mic1-> getColorProxy());
?>
</pre>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment