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 trialPatrick Neary
4,997 PointsPHP OOP challenge 5
Hey! can anyone tell me what's up with my code?
<?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;
public function getInfo() {
return "A " . $this->common_name . " is an " . $this->flavor . " flavored fish. The world record weight is " . $this->record_weight . "."
}
}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");
echo $bass->getInfo();
?>
Patrick Neary
4,997 PointsThank you Jason!
Sorry, this was my first time posting and I didn't explore all the available options.
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsOk, I tracked down the challenge.
You do want to put in the semi-colon but you also need to move your getInfo() function outside of the constructor function. Or you didn't close off your constructor function depending on how you want to look at it.
So make sure you have an opening and closing brace for your constructor function as well as an opening and closing brace for the getInfo
function and that it is not inside the constructor function.
Patrick Neary
4,997 PointsThank you for the help Jason. I really used to my editor automatically adding the other curly brace. My bad
Jason Anello
Courses Plus Student 94,610 PointsYou're welcome.
Having to type everything out in the code challenges makes you really appreciate what your editor is doing for you. :)
Shawn Flanigan
Courses Plus Student 15,815 PointsYou're missing a semicolon at the end of your return
statement in the getInfo()
function. Does that help?
Patrick Neary
4,997 PointsI added the semicolon but it still isn't passing :(
Thanks though
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Patrick,
I have fixed your code formatting for you.
This thread will show you how to post code: https://teamtreehouse.com/forum/posting-code-to-the-forum
Also, it's helpful to link to the challenge so anyone helping can review the challenge if needed.