"Swift Basics" was retired on May 31, 2020.

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 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
15,000 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!