Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Object-Oriented PHP Basics Understanding Classes Properties of a Class

I don't understand the error I'm getting here...

The error I'm getting is: Bummer: syntax error, unexpected '22' (T_LNUMBER) in fish.php on line 12. Can someone please point out what I'm doing wrong here? I corrected the double quotes and still I get the same error.


class Fish {
    public $common_name;
  public $flavor;
  public $record_weight;

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


1 Answer

This is a good example of how sometimes errors can be misleading. Take a look at the line above line 12, because that's actually where the error is. You've written:

$bass->flavor = "Excellent';

You've started the value with a double-quote but ended it with a single-quote, which means the string is still open. PHP keeps evaluating until it gets to something it can't figure out, on the next line, where you finally close the double-quote with what you thought was a new double-quote. So that's when PHP throws the error. Errors can sometimes be confusing.

Close your double-quote in line 11 and all should be well.