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

what the wrong in my code

what the wrong in my code

fish.php
<?php

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

  function__ counstructor( $common_name,$flavor,$record_weight){
    $this->common_name=$name
      $this->flavor=$flavor
   $this->record_weight=$record_weight


  }

}

?>

2 Answers

Justin Black
Justin Black
24,793 Points
<?php
class Fish {

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

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

}

?>

Problem lies in that your code had no space between the word function and the two underscores. Also, in that there was a space between the two underscores and the rest of the method name. And, that your method name would have been __constructor when it should be __construct

Henrique Zafniksi
Henrique Zafniksi
8,560 Points

The word "function" must be separated from "__construct", also, you wrote "counstructor" therefore you have a typo in your code. A good hint to be looked upon is the color of the words aforementioned: function and __construct are PHP reserved expressions, and should, together with many others like 'class' and 'public', appear colored when written.

It is good practice to maintain good readability on your code by using the right indentation, always giving proper spacing between variables, commas and those equal signs:

<?php

class Fish {

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

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

}

?>

As you can see, it looks better to read.