From cd05afac1ac3686a078a8be12398a01550d7258f Mon Sep 17 00:00:00 2001 From: Raghav <raghavsmart1213@gmail.com> Date: Mon, 3 Mar 2025 07:28:56 +0000 Subject: [PATCH] Test with () and changed string with ucwords() --- _includes/Mic.class.php | 18 ++++++++++++++++-- test.php | 8 +++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/_includes/Mic.class.php b/_includes/Mic.class.php index 20a968c..05c5d0b 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 f8c866c..3d10261 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 -- GitLab