diff --git a/_includes/Mic.class.php b/_includes/Mic.class.php index 20a968cdb1553f888d7116da7c5b8a4aca7e6778..05c5d0b630f34b15f0a64ef6f36d92642136ff46 100644 --- a/_includes/Mic.class.php +++ b/_includes/Mic.class.php @@ -11,7 +11,21 @@ class Mic // Creating methods.. public function setLight($light){ - print($light); - print($this -> light); + print($light);//Returns parameter's value + + // $this keyword is used to specify the variable inside class. + print($this -> light);//Returns Object variable value. + } + + // Call and change model name to first word as uppercase + public function setModel($model){ + // Store $model values to model with $this. + $this -> model = ucwords($model); //ucwords() converts 1st letter string as uppercase. + + return $this-> model; + } + + public function getModel(){ + print($this-> model); } } diff --git a/test.php b/test.php index f8c866c89f8e7717f31f9181e9214474860fe4e6..3d1026190d6ba5f0e43477e3530010e17ecbdff6 100644 --- a/test.php +++ b/test.php @@ -25,13 +25,19 @@ $mic1 = new Mic(); $mic2 = new Mic(); - $mic1->brand = "Toyota"; + $mic1->brand = "Switf"; $mic2 -> brand = "Hyundai"; + + // Adding values to $light with $this keyword $mic1 -> light = "RGB"; $mic1 -> setLight("yellow"); + $mic1 -> setModel("toyata innova"); + + $mic1-> getModel(); printf("mic1 = %s\n", $mic1 -> brand); printf("mic2 = %s", $mic2 -> brand); + ?> </pre> \ No newline at end of file