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 trialAnna Takang Nchongarrey-Oben
7,365 PointsAdd a property named species to the Trout class
I think I did it correctly, I wonder why it is not working
<?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 function __construct($name, $flavor, $record, $species)
{
parent::__construct($name, $flavor, $record);
$this->species = $species;
}
}
?>
2 Answers
Jonathan Grieve
Treehouse Moderator 91,253 PointsTry removing those periods (full stops) in your public function
<?php
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;
}
?>
If i remember correctly the assignment operator is the right way to assign the variables here.
Jenny Veens
10,896 PointsHi Anna,
I think you might be getting a bit ahead of yourself here :)
The question asks to 'Add a property named species to the Trout class' - It doesn't yet mention anything about the constructor. Make sure the $species variable is present in your class, so that later you will be able to access it with construct.
Here's a bigger hint: Notice how the variables are declared at the beginning of the Fish class,
public $common_name;
public $flavor;
public $record_weight;
Use the above as a guide for adding a property to Trout.
Anna Takang Nchongarrey-Oben
7,365 PointsI am on 6/7 and it keeps telling me it looks like one is no longer passing. I closed the brackets correctly
Jenny Veens
10,896 PointsAnna could you post what your code looks like now at stage 6/7?
Anna Takang Nchongarrey-Oben
7,365 PointsAnna Takang Nchongarrey-Oben
7,365 PointsI did that and it still did not work