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 (Retired) Properties and Methods Mid-Course Challenge

Kevin Pryce
Kevin Pryce
3,051 Points

Assign $name parameter to the common_name property using $this to refer to the current object.

In the code challenge for Object-oriented PHP basics, need help with step 3 of 5.

Code challenge instructs me: In the new constructor method, assign each of the properties on the Fish class with its corresponding parameter variable.

My code is:

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

  function __construct ( $name, $flavor, $record ) {
    $this->name = $common_name;
    $this->flavor = $flavor;
    $this->record = $record_weight;
  }
}```

Error I am receiving is:
Be sure that the $name parameter is assigned to the common_name property using $this to refer to the current object.

Can not figure out where my error is.

```fish.php
<?php 

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

  function __construct ( $name, $flavor, $record ) {
    $this->name = $common_name;
    $this->flavor = $flavor;
    $this->record = $record_weight;
  }
}

?>

2 Answers

try change in the __construct this

$this->name = $common_name;
$this->record = $record_weight;

to

$this->common_name = $name;
$this->record_weight= $record;

I have the same issue -- keep being sent back to step 1. The code suggested above does not check as correct for me.