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 Understanding Classes Methods of a Class

Is there a way to get the solution to a problem if I'm stuck?

I know I can skip forward, but this way I'm missing info. I'd like to know what am I doing wrong to be able to move forward with learning.

fish.php
<?php

class Fish
{
    public $common_name;
    public $flavor;
    public $record_weight;
  public function getInfo(){
  return $this->$common_name . "is an" . $flavor . "flavored fish. The world record weight is" . $record_eright . ".";
  }
}

$bass = new Fish();
$bass->common_name = "Largemouth Bass";
$bass->flavor = "Excellent";
$bass->record_weight = "22 pounds 5 ounces";

echo $bass getInfo();
?>

2 Answers

Ricardo Vermaat
Ricardo Vermaat
150 Points

This looks mostly fine to me, but in your function getInfo you have $record_eright in your output instead of $record_weight. Probably just a typo.

Also, you forgot a -> on your last line. It should be $bass->getInfo();. You are calling to a function of the bass object. Just like the variables you set for that object, you need a -> for the functions.

Thanks for the reply. I guess just getting the solution would be too easy, writing correct code is very important if you don't want to go crazy later. I did find the errors and solution after posting this question by reviewing the previous videos and figuring out that I can localize the problem more precisely if I break the problematic line into smaller pieces on different lines. I always seem to miss important details from the videos and also prone to make typos, so I should work on correcting that early on. Learning this way takes a lot longer, but developers do have to debug all the time so we better get used to it.

Ricardo Vermaat
Ricardo Vermaat
150 Points

Having a decent editor helps if you make a lot of typos. A good editor will auto complete your variables and function names so you don't have to type them out every time. They will even work for external classes once you get to that point. They will even highlight things if you do end up making a typo.

There are plenty of free editors out there, I use Netbeans for PHP myself. Maybe something to look into.

Cliff Jackson
Cliff Jackson
2,887 Points

I find using work spaces is hard to spot errors in code, i don't always put the code in Atom as well but like someone else said the errors show up better because of the colors on the text. Like you i miss details from the videos on PHP one reason is the tutor is going way too fast and seems to forget she's a teacher as well as a developer.