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

Can't figure out how to return properties from the getInfo() method in Object-Oriented PHP Basics

getInfo() { return $this->common_name . $this->flavor . $this->record_weight; } I can't get passed this, nothing seems to work.

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;
}
  public getInfo()
{
  return $this->common_name;
}
}
$bass = new Fish("Largemouth Bass","Excellent","22 pounds 5 ounces");
$bass->getInfo();

?>

4 Answers

Please note that you can not define a function like this in PHP. You have to use it like this

public function getInfo() { return $this->common_name. $this->flavor. $this->record_weight; }

Now echo the result like this

echo $bass->getInfo();

Happy coding!

Edited to move from comment to answer.

Brock,

In part 5 you have to read the instructions carefully. It's asking you to return a phrase with the properties included. Remember it says you can use the phrase: "A Largemouth Bass is an Excellent flavored fish. The world record weight is 22 pounds 5 ounces." as an example. Use the phrase but substitute the words that were pre-filled in (Largemouth Bass, Excellent, etc) with the properties. HINT: using double-quotes allows you to embed the properties without escaping the string. Just make sure you reference the properties like the videos explained. Also, remember how to create a function by using the function keyword. Hope this helps.

Cheers!

To elaborate on what Shawn said regarding quotes, here is what you get with single and double quotes:

<?php
$name = 'Ted';

echo 'My name is $name.';
// Returns: My name is $name.

echo "My name is $name.";
// Returns: My name is Ted.

Otherwise, the other two comments should enable you to solve this challenge. If you still have problems, please post here again stating so. Also, please mark Best Answer for the answer that you find helps you the most and upvote any answer that was helpful.

Thanks guys, I made it through the challenge. I forgot the function keyword when defining the function. You were all helpful. :-)

Cheers!