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 trial

PHP Object-Oriented PHP Basics (Retired) Inheritance, Interfaces, and Exceptions Final Challenge

Stating 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?

Robert Walker
Robert Walker
17,146 Points

You missed the double underscore after parent::

Should be parent::__construct($name,$flavor,$record);

6 Answers

Benjamin Lim
Benjamin Lim
17,880 Points

This got me through. Hope this helps!

    class Trout extends Fish{
      function __construct($name, $flavor, $record){
        Fish::__construct($name,$flavor,$record);
      }
    }
Mike Costa
PLUS
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);

This might help

<?php
class Trout extends Fish {
  function __construct($name, $flavor, $record) {
  parent::__construct($name, $flavor, $record);
  }
?>
thomas howard
thomas howard
17,572 Points

how's San Fran. Work thin out there?

I have the same problem, this doesn't work for me:

class Trout extends Fish { function __construct($name,$flavor,$record){ parent::construct; } }

'''php class Trout extends Fish { function construct($name,$flavor,$record) { parent::construct($name,$flavor,$record);} } '''php

hi 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

Make 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);
  }
}