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

Objects in PHP Forum

View Course » View Exercise

154 points
307bf2d1de962509858ade4fde1a7cbd?s=140&d=retro
Submitted by
jjd1
almost 2 years ago

It passes me for the next lesson but doesnt display the result in the window. Where am i wrong.

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

    public function __construct($name){
        $this->name = $name;
   }
   public function bark(){
   return "Hello i am a dog. My name is ".$this->name."Welcome to my den";
   }
   public function greet(){
       return "Warning".$this->name."I will bite you!";
   }
   }
   $dog1 = new Dog('Barker');
   $dog2 = new Dog('Amigo');
   echo->greet();
   echo->bark();

   ?>

0 votes

permalink

You're not echoing the variables you created. Should work if you change your echo portions to
echo $dog1->bark();
echo $dog2->greet();

796 points
031d89dc39d995aba442becfbe8382a6?s=140&d=retro
Submitted by
kcorbluigi
almost 2 years ago