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

Adam Siwiec
Adam Siwiec
12,070 Points

Help Please!

Ok so Im working on this challenge and I am on the last step, and I am am supposed to echo some of the parameters, and I can't seem to figure out what works.

Could anyone tell me what I am doing wrong and/or what I need to add.

fish.php
<?php

class Fish {
  public $common_name = 'Hi';
  public $flavor = 'Hello';
  public $record_weight = 0;

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

}
  function getInfo() {
    echo "A $this->common_name is an $this->flavor flavored fish. The world record weight is $this->record_weight";
  }
  getInfo();
}

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


?>

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Adam, Your code is pretty much correct in Syntax, but there are a few things that the challenge did NOT ask for and therefore will not let you pass.

First, You do not need any values in your opening declaration of the three values.</br> Second, the task asks you to return the string not echo it.</br> Third, the task doesn't ask for the function to be called.</br>

Other than that, good job. Just remember that challenges are VERY picky and VERY strict. If you take away or add it will more often than not... not let you pass.

Here is the corrected code:

<?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;
  }
  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') 

?>

Keep Coding! :)

Adam Siwiec
Adam Siwiec
12,070 Points

There also is a semicolon after the echo

Greg Kaleka
Greg Kaleka
39,021 Points

He actually did include it. The color scheme for PHP leaves much to be desired... very difficult to see!