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

Jake Hudson
Jake Hudson
7,841 Points

I can't get around this error. not sure where it is.

"Be sure the $name parameter is assigned to the common_name property. Use $this to refer to the current object."

Perhaps I'm too sleep deprived to figure out why I can't get around this error?

fish.php
<?php 

class Fish {
public $common_name = "default name";
  public $flavor = "default flavor";
  public $record_weight = "record that weight yo.";

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

}


?>

2 Answers

Tommy Choe
Tommy Choe
38,156 Points

Hey Jake,

I was actually making the same mistake not too long ago. You're assigning the passed parameter "$name" to a property called name. The only problem is that you don't actually have one. Yours is called $common_name. So all you need to do is change it so that you're assigning $name, $flavor, and $record to the appropriate property names.

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

Let me know if you're having trouble getting through the rest of the challenge.

Change

$this -> name to $this -> common_name

And

$this -> record to $this -> record_weight