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 Object-Oriented PHP Basics (Retired) Properties and Methods Mid-Course Challenge

Alejandro Hernandez
Alejandro Hernandez
7,629 Points

OOPHP Course - Not sure what i am doing wrong here...

<?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;
    }

}

?>
Philip Cox
Philip Cox
14,818 Points

Hi. This is just a guess. Do you need to set your function as public and also return it?

5 Answers

Mike Costa
PLUS
Mike Costa
Courses Plus Student 26,361 Points

PHP variables need the $ in front of them. For objects, to access the member variables within a class, you would need $this->commonname, $this->flavor, ect ect.

Alejandro Hernandez
Alejandro Hernandez
7,629 Points

No Luck w/that.

<?php

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

}

?>
Michael Collins
Michael Collins
433 Points

If you are trying to get a lesson to accept this an answer, I can't help with that. But if you describe what you want your code to do and what is and is not doing, I can help with that.

Mike Costa
PLUS
Mike Costa
Courses Plus Student 26,361 Points

PHP variables need the $ in front of them. For objects, to access the member variables within a class, you would need $this->commonname, $this->flavor, ect ect.