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

Oops! It looks like Task 1 is no longer passing

I cannot pass task 2 of 2. See code, please help!

fish.php
<?php 

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

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

1 Answer

Daniel Gauthier
Daniel Gauthier
14,999 Points

Hey Daniella,

In order to assign values to the object's properties, you need reference the object first, then add the -> sign prior to noting which property you're looking to assign the value to.

Also note that you don't use the $ when noting the properties.

The following code will pass:

<?php 

class Fish {

  public $common_name;
  public $flavor;
  public $record_weight;

}

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

?>

Good luck with the course!