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 trialRenata Hernández Sánchez
209 PointsChallenge 2 of 5
This is my code as per instructions, but I don't know what I'm doing wrong :(
Instructions say: "Define a constructor on the Fish class with 3 parameters, in order, named $name, $flavor, and $record." So I thought that's what I did?? I keep getting the ** "Bummer! Try again!" ** message.
Any thoughts are appreciated, thanks!
<?php
class Fish {
// properties with default values
public $name = 'This is the default name.';
public $flavor = 'Chocolate :P';
public $record = '200 lbs';
// constructor method
public __construct($name, $flavor, $record) {
$this->name = $name;
$this->flavor = $flavor;
$this->record = $record;
}
}
?>
3 Answers
Jason Anello
Courses Plus Student 94,610 PointsThe code you posted in the comment is closer to the correct code. You don't have the correct public variable names in the code you posted first.
Try function __construct
not public
Shawn Gregory
Courses Plus Student 40,672 PointsHello,
Your problem stems from the fact that the constructor is a class method and with all methods, they are PHP functions. You are not required to put PUBLIC before the constructor since PHP knows it's going to be public, however because it is a function, you need to declare it like you would a function.
Cheers!
Renata Hernández Sánchez
209 PointsD'oh! I see now, I seriously have to clean my glasses... Thank you guys!
Renata Hernández Sánchez
209 PointsRenata Hernández Sánchez
209 PointsAlso tried this:
Still no luck :|