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 trialLeonid Fishler
1,708 PointsPHP 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
Leonid Fishler
1,708 Pointsfigured it out, sorry for bothering with just a basic question.
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
Andrew McCormick
17,730 Pointslook at where your "$" is at.
Leonid Fishler
1,708 PointsThanks!
Leonid Fishler
1,708 PointsI 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
11,738 PointsNo problem Leonid; it's how we learn.
Hamza Pavlovic
7,411 Points"$this->variable" not this->$variable.