PHP7: Adjust the speak method in the dog.php file to return the bark string but
ID: 3903985 • Letter: P
Question
PHP7:
Adjust the speak method in the dog.php file to return the bark string but not print it. Also adjust the call to the method in the lab.php file to display the output of the string. You can accept the string form the method and print the string in one line of code using syntax similar to the following: print $lab->speak();
dog.php:
<?php
class Dog
{
private $dog_weight = 0;
private $dog_breed = "no breed";
private $dog_color = "no color";
private $dog_name = "no name";
function get_properties()
{
return "$this->dog_weight,$this->dog_breed,$this->dog_color.";
}
}
?>
lab.php:
<?php
Require_once("e36dog.php");
$lab = new Dog;
$dog_properties = $lab->get_properties();
list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties);
print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color.";
?>
Explanation / Answer
dog.php
<?php
function speak(){
return bark;
}
class Dog
{
private $dog_weight = 0;
private $dog_breed = "no breed";
private $dog_color = "no color";
private $dog_name = "no name";
function get_properties()
{
return "$this->dog_weight,$this->dog_breed,$this->dog_color.";
}
}
?>
lab.php:
<?php
Require_once("e36dog.php");
$lab = new Dog;
$dog_properties = $lab->get_properties();
list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties);
print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color.";
print $lab->speak();
?>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.