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 trialRaul Chiru
Courses Plus Student 2,776 Pointsplease :D
Add a property named species to the Trout class.
<?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{
function __construct($name, $flavor, $record){
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
$species = new Fish();
}
?>
3 Answers
Samuel Webb
25,370 PointsYou're not adding the property correctly. A property would be added in the same way the Fish
class adds the common_name
, flavor
and record_weight
properties. Just in the Trout
class.
Raul Chiru
Courses Plus Student 2,776 Pointsit dosen't work
Samuel Webb
25,370 PointsOops, I added the dollar sign before public. It's supposed to be before species.
public $species;
Raul Chiru
Courses Plus Student 2,776 Pointsthanks, man!
Raul Chiru
Courses Plus Student 2,776 PointsRaul Chiru
Courses Plus Student 2,776 PointsI don't understand :D
Samuel Webb
25,370 PointsSamuel Webb
25,370 PointsIt might be useful to re-watch the video that discusses adding properties to classes again. Sometimes it's really helpful to check out some of the videos multiple times until you have a more solid understanding of what's being taught. PHP becomes really difficult, really quickly and without a good grasp on the basics, you'll end up lost.
But to answer your question:
Edit: Fixed small typo.