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

Maxwell Kendall
seal-mask
.a{fill-rule:evenodd;}techdegree
Maxwell Kendall
Front End Web Development Techdegree Student 12,102 Points

OO PHP Task 2

Cannot figure out how I am using the Construct method wrong...?

fish.php
<?php 

class Fish {

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

}

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

?>

4 Answers

Hi,

I think your are pretty much there other than a extra } you have and spaces on the $this->property_name areas of the __construct.

So from your above code it should be like this :

<?php

class Fish
{

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

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

?>

Hope this helps, it has been a while since I did a little php :) Craig

Sorry,

I have had a go of the challenge and this has passed :)

<?php 

class Fish {

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

  function __construct($name, $flavor, $record){

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

  }
    public function getInfo(){
        // using concatination you can call the defined method objects
        return "A" . $this->common_name . " is an " . $this->flavor . " fish. The world record weight is " . $this->record_weight;
    }
}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");

?>

Craig

Much appreciated!