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

Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

create a method on fish

Help I can't get past this!

fish.php
<?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;
  }

  //method
  public function getinfo(){
   return "The $this->name . is a $this->flavor . flavored fish with a favored weight of . $this->record; 
  }
}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");

echo $bass->getinfo();

?>
narvesh pradhan
narvesh pradhan
2,958 Points

return "A". $this ->common_name . "is a " . $this ->flavor . "fish" . "the world record weight is ". $this-> record_weight ; this will print " a largemouth bass is a excellent flavour fish. the world record weight is 22 pounds and 5 ounces.'' hope this will help you.

3 Answers

Sean Do
Sean Do
11,933 Points

You can already tell by looking at your pasted code. Check your quotes on your return statement, either you didn't close it or you're concatenating wrong.

Here's my results:

<?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() {
    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");
?>
Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

Thank you, I was using the concatenation wrong and I was referencing from the construct instead of the class.

I recently learned that the original code could work with some minor tweaks. When PHP has a variable enclosed in a double quote it will process the variable and input its value. It will not for single quotes. So if you take out the concatenation periods and punctuate properly, it should display the way you want. That is not to say that it will pass the challenge, though.