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

Brian Platt
Brian Platt
5,009 Points

Having trouble with the getInfo assignment, any suggestions?

On the Mid-course Challenge I am having difficulties with the getInfo to print out a full sentence, and don't know where to begin. Any suggestions? I think I am getting caught up the $p from the exercise, I am not sure where that fits in.

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;

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


?>

1 Answer

I can help you with your question, but first a observation about formatting. While your current code is correct, formatting will help you see what is happening better. This is how I would format it. The changes are subtle, but make a difference it figuring out the 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;
    }

}

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

Some of the changes are to fit the suggested standards. I think Treehouse does a poor job teaching proper formatting to meet standards. I wish they did it from the very beginning so it was second nature.

Right now your code does not do anything with the arguments you pass to the class and the class has no output. First, you need to create a method (really a function in a class) in your class. I left a space after the constructor for that method. Inside the method you need to tell it what you want the text to say and then return the result. Then, after you instantiate the new Fish, you need to echo a call to the method that returns the text you want to say.

I will let you try to figure it out with those directions. Please let me know how it goes and if you need more help.

Brian Platt
Brian Platt
5,009 Points

Nice I got it, thanks for the formatting help, it's an easy thing to overlook since TTH allows you to pass even if your syntax isn't perfect.