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 9: class Pet {
public $name;
private $sound;
public $species;
public function __construct($name, $sound){
$this->name = $name;
$this->sound = $sound;
}
public function get_name(){
return $this->name;
}
public function get_species(){
return $this->species;
}
public function set_species($species){
$this->species = $species;
}
public function speak(){
return $this->sound;
}
}
/*08: Create three instances of the Pet
class. $pet1, $pet2, and $pet3.
$pet1 should be named "Spot" and makes the sound "Moo!"
$pet2 should be named "Lucky" and makes the sound "Bark!"
$pet3 should be named "Daisy" and makes the sound "Quack!"
Call the speak method for each Pet instance and output
the result.*/
$pet1= new Pet("Spot", "Moo!");
$pet2= new Pet("Lucky", "Bark!");
$pet3= new Pet("Daisy", "Quack!");
/*09: Use the set_species method on each pet
instance from above.
$pet1 is a "Cow"
$pet2 is a "Dog"
$pet3 is a "Duck"
Afterwards, create a $petArray that contains
all 3 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.
*/
$pet1->set_species("Cow");
$pet2->set_species("Dog");
$pet3->set_species("Duck");
$petArray =[$pet1, $pet2, $pet3];
foreach (array_reverse($petArray) as $pet){
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!