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 trialPaul Mather
3,313 PointsOOP Construct Method - code incorrect?
I'm doing the OOP track and, when writing the exact same code as in the video, it echos out "default_name" instead of what it does in the test (obviously my text differs slightly from that in the video, but everything else is the same).
Any idea why it's displaying "default_name" instead of "Testing"?
class Product {
public $name = "default_name";
public $price = 0;
public $desc = "default description";
function __contruct($name, $price, $desc) {
$this->name = $name;
$this->price = $price;
$this->desc = $desc;
}
public function getInfo() {
return "Product Name: ". $this->name;
}
}
$p = new Product();
$shirt = new Product("Testing", 34.99, "An amazing T-Shirt");
echo $shirt->getInfo();
?> ```
3 Answers
Jesse Richard
1,899 PointsCheck out your constructor name. It's very, very close....
Casey Ydenberg
15,622 Pointsconstruct is misspelled
Paul Mather
3,313 PointsOh wow, i can't believe i missed that! I looked over it at least 10 times.
Thanks Jesse, i really appreciate you taking a look.
Jesse Richard
1,899 PointsNo problem. Happens to me all the time!