diff --git a/_includes/Mic.class.php b/_includes/Mic.class.php index 05c5d0b630f34b15f0a64ef6f36d92642136ff46..42e49bc68776c9865caa1199b888e790a3502697 100644 --- a/_includes/Mic.class.php +++ b/_includes/Mic.class.php @@ -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(); + } + } diff --git a/test.php b/test.php index 3d1026190d6ba5f0e43477e3530010e17ecbdff6..ab351713597a7a9f89167e824372a28d40c65134 100644 --- a/test.php +++ b/test.php @@ -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