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.

fish.php
<?php 

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.