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

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

}

?>

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

5 Answers

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.

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

}

?>

Not an answer. But here is a great article on beginning OOP in PHP. http://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762

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.

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.

Good call Mike. Thnx a million.