Question: what is wrong here with part 9 : class Pet { public $name; private $sound; public $species; public function _ _ construct ( $name, $sound
what is wrong here with part : class Pet
public $name;
private $sound;
public $species;
public function construct$name, $sound
$thisname $name;
$thissound $sound;
public function getname
return $thisname;
public function getspecies
return $thisspecies;
public function setspecies$species
$thisspecies $species;
public function speak
return $thissound;
: Create three instances of the Pet
class. $pet $pet and $pet
$pet should be named "Spot" and makes the sound "Moo!"
$pet should be named "Lucky" and makes the sound "Bark!"
$pet should be named "Daisy" and makes the sound "Quack!"
Call the speak method for each Pet instance and output
the result.
$pet new PetSpot "Moo!";
$pet new PetLucky "Bark!";
$pet new PetDaisy "Quack!";
: Use the setspecies method on each pet
instance from above.
$pet is a "Cow"
$pet is a "Dog"
$pet is a "Duck"
Afterwards, create a $petArray that contains
all pet instances.
Loop through the array in reverse order
and output the name value for each pet
object in the array on a new line.
Not sure about the reverse?
Look at the PHP docs.
$petsetspeciesCow;
$petsetspeciesDog;
$petsetspeciesDuck;
$petArray $pet $pet $pet;
foreach arrayreverse$petArray as $pet
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
