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

Abiodun Oke
Abiodun Oke
4,015 Points

fish method

I couldn't get the last challenge, below is my response

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

echo $bass->getInfo();

<?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');
echo $bass->getInfo();
?>

4 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi Abiodun, I think the issue is the following line:

<?php
 return "A" $this->common_name "is an" $this->flavor "flavored fish.The world record weight is" $this->record-weight;
?>

you have used record-weight when you need to use record_weight, try changing it to the following:

<?php
 return "A" .  $this->common_name . "is an" . $this->flavor . "flavored fish.The world record weight is" . $this->record_weight;
?>

Hope that helps!!

Edit: You also need to concatenate your statement by adding "." in between each part

Abiodun Oke
Abiodun Oke
4,015 Points

I have changed the property to record_weight but it didn't help.

Abiodun Oke
Abiodun Oke
4,015 Points

Done but not working,thanks.

Grace Kelly
Grace Kelly
33,990 Points

Hmm that's strange I've just inputted the edited code into the challenge and it passed fine, here is your code with the changes made to it, if you want to try it again:

<?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; //used record_weight and added concatenation
  }
}

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

?>
Abiodun Oke
Abiodun Oke
4,015 Points

I have no idea how it happened but the last code worked,thank you.

I think there may also be an issue with the spaces between the text and variables. Try this (I have not tested it):

return "A " . $this->common_name . " is an ' . $this->flavor . " flavored fish.  The world record weight is " . $this->record_weight . ".";