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 trialRobert Wilde
Courses Plus Student 5,400 PointsStating my answer is wrong but don't know why
So the question is: "Create a constructor for the Trout class with three parameters in order: $name, $flavor, and $record. Call the parent constructor inside the new constructor."
and I created
class Trout extends Fish { function construct($name,$flavor,$record){ parent::construct($name,$flavor,$record); } }
what have I missed?
6 Answers
Benjamin Lim
17,880 PointsThis got me through. Hope this helps!
class Trout extends Fish{
function __construct($name, $flavor, $record){
Fish::__construct($name,$flavor,$record);
}
}
Mike Costa
Courses Plus Student 26,362 Points__construct() is a magic method used by php that tells the object being created how it should be formed. Magic methods are called by php implicitly. So when you create a class Car, you can optionally pass in values to the object being created so that object will have those values. http://php.net/manual/en/language.oop5.magic.php
<?php
class Car {
public $wheels;
public function __construct($numberOfWheels){
$this->wheels = $numberOfWheels;
}
}
$car = new Car(4);
Elijah Collins
19,457 PointsThis might help
<?php
class Trout extends Fish {
function __construct($name, $flavor, $record) {
parent::__construct($name, $flavor, $record);
}
?>
thomas howard
17,572 Pointshow's San Fran. Work thin out there?
Damjan Pavlica
8,700 PointsI have the same problem, this doesn't work for me:
class Trout extends Fish { function __construct($name,$flavor,$record){ parent::construct; } }
Syed Mahbub
8,780 Points'''php class Trout extends Fish { function construct($name,$flavor,$record) { parent::construct($name,$flavor,$record);} } '''php
MUZ140592 Victor Mutasa
4,260 Pointshi guys, i have the same problem this code wont work for me, OR IS IT WHERE I AM PLACING IT WHICH IS WRONG? PLEASE HELP
Mark Truitt
17,230 PointsMake sure that you are closing both sections of the code too.
class Trout extends Fish {
function __construct($name, $flavor, $record) {
Fish::__construct($name, $flavor, $record);
}
}
Robert Walker
17,146 PointsRobert Walker
17,146 PointsYou missed the double underscore after parent::
Should be parent::__construct($name,$flavor,$record);