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

PHP OOP coding challenge question

Hey I am at the coding challenge where it asks you to go into the construct of class Fish and assign variables you put into the construct, to ones defined previously I added this code to accomplish it : '''php this->$name = $common_name; this->$flavor = $flavor; this->$record = $record_weight;''' I put this into my construct function. Its apparently wrong though.

7 Answers

figured it out, sorry for bothering with just a basic question.

Aaron Elliott
Aaron Elliott
11,738 Points
  public $star_name;
  public $color;
  public $total_mass;

  function __construct($name, $color, $mass){
     $this->star_name = $name;
     $this->color = $color;
     $this->total_mass = $mass;
  }

}

Hi Leonid,

I think the variable names make this one kind of tricky. I've included a similar Constructor for you to review, and see where you might be making your mistake.

Thanks

Thanks!

I changed it to this and it still doesnt work '''<?php

class Fish {

public $common_name = 'default name'; public $flavor = 'default flavor'; public $record_weight = 0;

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

}

?>'''

Aaron Elliott
Aaron Elliott
11,738 Points

No problem Leonid; it's how we learn.

"$this->variable" not this->$variable.