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

issue with getInfo method in child class

I have tried to create the required get-info method adding the extra property from the child but it is not correct. The example in the question has no reference to the species but it is need in the method. Is there an error there

4 Answers

Scott Evans
Scott Evans
4,236 Points

Below is my example implementation of the getInfo() method. As you can see i have concatenated the many different variables to create the same string output as the challenge specifies. Dont forget when classes are extended, the child class has access to all of its public or protected variables or methods of the parent class.

class trout extends Fish {
  public $species;
  function __construct($name, $flavor, $record, $species){
    $this->species = $species;
    parent::__construct($name, $flavor, $record);
  }

  function getInfo(){
     return $this->species." ".$this->common_name.
       " tastes ".$this->flavor.". The record ".$this->species." ".$this->common_name." weighed ".$this->record_weight;
  }
}

Hope this helps!

Scott Evans
Scott Evans
4,236 Points

Could you post your code please Robert, so i could more easily assist you?

Hi , I had just finished that course. Ok I believe that you need to declare the parent's construct method as the first thing in the child class's construct method. secondly isnt the $this->record === $this->record_weight; Cheers

Scott Evans
Scott Evans
4,236 Points

I have also completed the challenge, my code was placed to help Robert. You noticed my mistake with the $this->record, i have corrected it :D

oh lol sorry mate. I didnt realize that you were answering Robert :) cheers