This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Objects in PHP Forum

View Course » View Exercise

91 points
C0e6067ef2b8c8c479ad93bba8b9de3c?s=140&d=retro
Submitted by
mikey10241
over 2 years ago

8/10, displays all but my objects name, what's wrong?

<?php
class Dog {
public $numLegs = 4;
public $name;
function __constructor($name) {
$this->name = $name;
}

  function bark() {
      return "Woof!";
  }
  function greet() {
      return "hi my name is" . $this->name. "";
  }


  }
  $dog1 = new Dog("Barker");
  $dog2 = new Dog("Amigo");
  echo $dog1->bark();
  echo $dog2->greet();
  ?>

2 votes

permalink

try this.

<?php
class Dog {
public $numLegs = 4;
public $name;

          public function __construct($name) {
              $this->name = $name;
          }

          public function bark() {
              return "Woof!";
          }

          public function greet() {
              return "Hello. I am" . $this->name;
          }
      }

      $dog1 = new Dog("Barker");
      $dog2 = new Dog("Amigo");

      echo $dog1->bark();
      echo $dog2->greet();
    ?>

254 points
8956207c396ab97e402eca36c2a48e07?s=140&d=retro
Submitted by
Rohini Singh
over 2 years ago


0 votes

permalink

same "error" ... please help

103 points
55d21447d3292f743300074d_218571341
Submitted by
Portsl
over 2 years ago


0 votes

permalink

I think you forgot to write public function _construct instead of function _construct

Also public function greet

223 points
9ed91e7603d77adf36c1005fbf75cf00?s=140&d=retro
Submitted by
fardina
over 2 years ago