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!
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
Luke Briedis
3,600 PointsPHP OO Basics 6/7 final challenge not passing
Not sure why this isn't passing. It's 1:1 with the examples used in the videos. I even tried using the echoing what the proposed example is, though it shouldn't require that exactly right ?
Add a getInfo method to your Trout class that returns a string containing the common_name, flavor, record_weight, and species properties. For example, on our brook trout it might return "Brook Trout tastes Delicious. The record Brook Trout weighed 14 pounds 8 ounces."
<?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;
}
public function getInfo() {
$output = "The {$this->common_name} is an awesome fish. ";
$output .= "It is very {$this->flavor} when eaten. ";
$output .= "Currently the world record {$this->common_name} weighed {$this->record_weight}.";
return $output;
}
}
class Trout extends Fish {
public $species;
public function __construct($name, $flavor, $record, $species) {
parent::__construct($name, $flavor, $record);
$this->species = $species;
}
public function getInfo() {
return $this->species . $this->name . "tastes" . $this->flavor . ". " . "The record" . $this->species . $this->name . "weighed" . $this->record . ".";
}
}
$brook_trout = new Trout("Trout", "Delicious", "14 pounds 8 ounces", "Brook");
?>
10 Answers

Hampton Paulk
5,093 Pointshint for ya: public $common_name; is the actual property we want.

Brian Molkovich
11,333 PointsI got right answer, if somebody needs)))

Stewart Anderson
10,329 PointsI do. The "Bummer. Try again!" message seems to be the only "guidance" offered here. So frustrating.

Jorge Talancon
5,416 PointsStewart. I use sublime text on localhost to check out my errors. Because you do get a lot more information about your mistakes. Hope this tip works for you!
Denford Gudyanga
5,420 Pointspublic function getInfo() { return $this->species . $this->common_name . " tastes " . $this->flavor . ". The record " . $this->species . $this->common_name . " weighed " . $this->record_weight . ".";
}

Elijah Collins
19,457 Points<?php
public function getInfo() {
return $this->species . $this->common_name . " tastes " . $this->flavor . ". The record " .
$this->species . $this->common_name . " weighed " . $this->record_weight . ".";
}
?>

Luke Briedis
3,600 PointsIc. Then I also have to use $record_weight instead of $weight. This is confusing, because in the earlier lesson, $weight becomes the variable for $record_weight, but upon reflection it was not extended this far in the lesson. One would just assume it would be addressed the same, I guess I know better now.

Grant LeMahieu
11,301 PointsI used the syntax in the parent class getInfo. Hint: name and species together

Eric Jackson
7,502 PointsI can't pass this. My code:
public function getInfo() { $output = "The {$this->species} is an awesome fish. "; $output .= "It is very {$this->flavor} when eaten. "; $output .= "Currently the world record {$this->common_name} weighed {$this->record_weight}."; return $output;
Any thoughts? Thanks.

Eric Jackson
7,502 PointsNevermind, was missing a bracket.

Steve Berrill
20,016 PointsHeres what I did
public function getinfo() {
return $this->species . $this->common_name . "tastes" . $this->flavor . ". The record" . $this->species . $this->common_name . "weighed" . $this->record_weight;
}
I actually struggled because I forgot to close the function!

Wouter Delken
3,553 PointsCan't believe it, I also forgot to close the function! Caught it now, so thanks for your comment :-)

Echo Yang
6,740 PointsAlso can't believe it... I tried many times and finally found forget to close it....

Jeremiah Wodke
3,192 PointsI know I'm way off but I don't understand why. Can somebody help me pass this brutal Quiz? lol
$brook_trout = new Trout("Trout", "Delicious", "14 pounds 8 ounces", "Brook"){
function __construct{
$this->Trout = $common_name;
$this->Delicious = $flavor;
$this->14_pounds_8_ounces = $record_weight;
$this->Brook = $species;
};
public function getInfo($common_name, $flavor, $record_weight, $species) {
$output = "The $common_name tastes $flavor. The record $species $common_name weighed $record_weight.";
return $output;
}
};

Hampton Paulk
5,093 PointsThe names of the arguments that you use in the construct are irrelevant, only the property name matters. However, you do need to name them with some level of readability.
for an example (this works but is not really readable to someone who did not write it):
public function __construct($arg1, $arg2, $arg3, $arg4) {
parent::__construct($arg1, $arg2, $arg3);
$this->species = $arg4;
}

Juan Jimenez
11,245 PointsI can't get it to pass following this example
class Trout extends Fish {
public function __construct($name, $flavor, $record, $species) {
parent::__construct($name, $flavor, $record);
$this->species = $species;
}
}
James Gill
Courses Plus Student 34,935 PointsJames Gill
Courses Plus Student 34,935 PointsIt's the actual property that we want where, exactly? This doesn't make sense to me in the context of this problem step.
[UPDATE] Ah, I figured it out. Later in the output string, we don't explicitly output the name and species, we just return the "common_name". I think what confuses many of us is that's not at all obvious in the return string given in the instructions, which say "The record Brook Trout weighed..." so, it looks like we simply insert $this->species and $this->name again for "Brook Trout" in that string.