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

Anna Takang Nchongarrey-Oben
Anna Takang Nchongarrey-Oben
7,365 Points

Add a property named species to the Trout class

I think I did it correctly, I wonder why it is not working

fish.php
<?php

class Fish
{
    public $common_name;
    public $flavor;
    public $record_weight;

    function __construct($name, $flavor, $record){
        $this->common_name = $name;
        $this->flavor = $flavor;
        $this->record_weight = $record;
    }

    public function getInfo() {
        $output  = "The {$this->common_name} is an awesome fish. ";
        $output .= "It is very {$this->flavor} when eaten. ";
        $output .= "Currently the world record {$this->common_name} weighed {$this->record_weight}.";
        return $output;
    }
}
  class Trout extends Fish{
   public function __construct($name, $flavor, $record, $species)
   {
    parent::__construct($name, $flavor, $record);
     $this->species = $species;
       }

  }

?>

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Try removing those periods (full stops) in your public function

<?php
 public function getInfo() {
        $output  = "The {$this->common_name} is an awesome fish. ";
        $output = "It is very {$this->flavor} when eaten. ";
        $output = "Currently the world record {$this->common_name} weighed {$this->record_weight}.";
        return $output;
    }
?>

If i remember correctly the assignment operator is the right way to assign the variables here.

Jenny Veens
Jenny Veens
10,896 Points

Hi Anna,

I think you might be getting a bit ahead of yourself here :)

The question asks to 'Add a property named species to the Trout class' - It doesn't yet mention anything about the constructor. Make sure the $species variable is present in your class, so that later you will be able to access it with construct.

Here's a bigger hint: Notice how the variables are declared at the beginning of the Fish class,

public $common_name;
public $flavor;
public $record_weight;

Use the above as a guide for adding a property to Trout.

Anna Takang Nchongarrey-Oben
Anna Takang Nchongarrey-Oben
7,365 Points

I am on 6/7 and it keeps telling me it looks like one is no longer passing. I closed the brackets correctly

Jenny Veens
Jenny Veens
10,896 Points

Anna could you post what your code looks like now at stage 6/7?