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) 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,362 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,362 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.