Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmo aly
7,003 Pointsweb link to code challenge https://teamtreehouse.com/library/final-challenge last section
last part to the code challenge unsure how to complete it correctly
<?php
class Fish
{
public $common_name;
public $flavor;
public $record_weight;
function __construct($name, $flavor, $record){
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
public function getInfo() {
$output = "The {$this->common_name} is an awesome fish. ";
$output .= "It is very {$this->flavor} when eaten. ";
$output .= "Currently the world record {$this->common_name} weighed {$this->record_weight}.";
return $output;
}
}
class Trout extends Fish{
public $species;
function __construct($name,$flavor,$record,$species){
$this->species=$species;
parent::__construct($name,$flavor,$record);
}
function getInfo($name,$flavor,$record,$species){
$common_name=$name;
$flavor=$flavor;
$record_weight=$record;
return $common_name."Trout tatses".$flavor.". The record".$species."Trout weighed".$record_weight;
}
}
$brook_trout= new Trout("Trout","Delicious","14 pounds 8 ounces","Brook");
$brook_trout->getInfo();
?>
1 Answer
Guilherme Oliveira
3,463 PointsHello!
In your function getInfo() you don't need to receive any arguments at all because your information is already saved on the object, so you can just remove all the variables inside the parenthesis. Also you don't need to do the " $common_name=$name; ... " part inside this function, because you already did it correctly on the constructor method (that is why your information is already saved on the object!), you can just remove these three attribution lines.
On the return part, the string that is being returned is going to be a little bit confuse, but it works, I recommend adjusting it for more clarity! Also, instead of $common_name, you are going to use the object notation, because you are making a reference to a property on the object itself, so it would be something like: $this->common_name, it applies on all properties.
And in the last line, you have to echo the method call if you want to see something on screen!
I hope it helps, if not, please ask again and I can try to answer it more clearly!