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

Alfredo Prince
Alfredo Prince
6,175 Points

I don't understand how this is wrong. $bass = new Fish("Largemouth bass", "Excellent", "22 pounds 5 ounces");

I am supposed to create a fish object named $bass withthe above features. and it tells me that task 1 will not pass

fish.php
<?php 

class Fish {
  public $common_name, $flavor, $record_weight;

  function __construct($name, $flavor, $record){
    $this-> common_name = $name;
    $this-> flavor = $flavor;
    $this-> record_weight = $record;


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


}
?>

You are doing great! However, the $bass stuff needs to go outside the Fish class. Try this:

<?php 

class Fish {
  public $common_name, $flavor, $record_weight;

  function __construct($name, $flavor, $record){
    $this-> common_name = $name;
    $this-> flavor = $flavor;
    $this-> record_weight = $record;
  }

}

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

?>

Hope that helps! :dizzy:

I saw you mentioned that it gave you an error "Did you set the common name for the bass to "Largemouth Bass"?" The answer to that is that the Treehouse code challenges are very picky, so you must do "Largemouth Bass" instead of "Largemouth bass".

Complete code:

<?php 

class Fish {
  public $common_name, $flavor, $record_weight;

  function __construct($name, $flavor, $record){
    $this-> common_name = $name;
    $this-> flavor = $flavor;
    $this-> record_weight = $record;
  }

}

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

?>

3 Answers

Alfredo Prince
Alfredo Prince
6,175 Points

Yes I tried that but it gave me this error: Did you set the common name for the bass to "Largemouth Bass"? Pass this as the first parameter of the Fish object.

I will show you the answer to that in my other answer. (I will update it.)

Alfredo Prince
Alfredo Prince
6,175 Points

Did you already change it? It looks the same.

Thanks for the help.

"bass" into "Bass". Told ya the challenges are picky.

Alfredo Prince
Alfredo Prince
6,175 Points

Yea I just saw your comment.

Thank you for your help!