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

Test with () and changed string with ucwords()

parent eed2a056
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,21 @@ class Mic ...@@ -11,7 +11,21 @@ class Mic
// Creating methods.. // Creating methods..
public function setLight($light){ public function setLight($light){
print($light); print($light);//Returns parameter's value
print($this -> light);
// $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);
} }
} }
...@@ -25,13 +25,19 @@ ...@@ -25,13 +25,19 @@
$mic1 = new Mic(); $mic1 = new Mic();
$mic2 = new Mic(); $mic2 = new Mic();
$mic1->brand = "Toyota"; $mic1->brand = "Switf";
$mic2 -> brand = "Hyundai"; $mic2 -> brand = "Hyundai";
// Adding values to $light with $this keyword
$mic1 -> light = "RGB"; $mic1 -> light = "RGB";
$mic1 -> setLight("yellow"); $mic1 -> setLight("yellow");
$mic1 -> setModel("toyata innova");
$mic1-> getModel();
printf("mic1 = %s\n", $mic1 -> brand); printf("mic1 = %s\n", $mic1 -> brand);
printf("mic2 = %s", $mic2 -> brand); printf("mic2 = %s", $mic2 -> brand);
?> ?>
</pre> </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