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 trialJames Ginns
2,731 PointsDoes the computer want a blank constructor?
I know how to do this in real life. I can't get any feedback as to what the computer actually wants. Do I need to declare my properties? Should I set them to public, private or protected? Should a constructor be blank? Or should I use it to give properties values ($this->property = $property)? I can't figure out why what I'm do is wrong. It's something a human would recognize, but not the machine.
<?php
class Fish {
private $name;
private $flavor;
private $record;
__construct($name, $flavor, $record){
$this->name = $name;
$this->flavor = $flavor;
$this->record = $record;
}
}
?>
1 Answer
Chris Shaw
26,676 PointsHi James,
Like with any other PHP code we write for classes such as methods we need to prefix the constructor with the function
keyword, a couple of other minor problems is your class properties name
and record
should be common_name
and record_weight
.
<?php
class Fish {
private $common_name;
private $flavor;
private $record_weight;
function __construct($name, $flavor, $record) {
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
}
Happy coding!