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

Seth Warner
Seth Warner
5,348 Points

why is my code not passing

Its just that return section that is confusing me.

fish.php
<?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;
  }
  public function getinfo(){
    return "$bass:". "A $name is an $flavor flavored fish. The world record weight is $record";

}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");

echo $bass->getinfo();
?>

2 Answers

samuel gustave, is essentially correct. I see two more issues. First, you should not have $bass in your return. That will kick an error because it is not part of the class. $bass is an instance of the class you define later. In real life, that will usually be in completely different files.

Second, you do not close the getInfo() method, so it appears that you never close the class. Your formatting helps identify this problem. it should look like this:

<?php
class Fish
{
// skipping code
    public function getInfo() {
        return "stuff";
   }  //this is indented to show it belongs to the getInfo function
}//this is not indented to show it closes the class.

Let us know if you have more issues.

samuel gustave
samuel gustave
7,341 Points

In that section, you're trying to access the $name, $flavor and $record variables. Those variable can only be used inside the __contruct method. If you want to access the corresponding properties of "Fish", you should write:

<?php
public function getinfo(){
    return "$bass:". "A $this->common_name is an $this->flavor flavored fish. The world record weight is $this->record_weight";
}

Edited code format so that it displays as code and with syntax highlighting.