Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


PHP OOP challenge 5

Hey! can anyone tell me what's up with my code?


class Fish {

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

  public function __construct($name, $flavor, $record){

    $this->common_name = $name;
    $this->flavor = $flavor;
    $this->record_weight = $record;

    public function getInfo() {
      return "A " . $this->common_name . " is an " . $this->flavor . " flavored fish. The world record weight is " . $this->record_weight . "."

$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");
echo $bass->getInfo();

Hi Patrick,

I have fixed your code formatting for you.

This thread will show you how to post code: https://teamtreehouse.com/forum/posting-code-to-the-forum

Also, it's helpful to link to the challenge so anyone helping can review the challenge if needed.

Thank you Jason!

Sorry, this was my first time posting and I didn't explore all the available options.

2 Answers

Ok, I tracked down the challenge.

You do want to put in the semi-colon but you also need to move your getInfo() function outside of the constructor function. Or you didn't close off your constructor function depending on how you want to look at it.

So make sure you have an opening and closing brace for your constructor function as well as an opening and closing brace for the getInfo function and that it is not inside the constructor function.

Thank you for the help Jason. I really used to my editor automatically adding the other curly brace. My bad

You're welcome.

Having to type everything out in the code challenges makes you really appreciate what your editor is doing for you. :)

Shawn Flanigan
Shawn Flanigan
Courses Plus Student 15,815 Points

You're missing a semicolon at the end of your return statement in the getInfo() function. Does that help?

I added the semicolon but it still isn't passing :(

Thanks though