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

Objects in PHP Forum

View Course » View Exercise

86 points
55b1dffc9376768c66000677_829824664
Submitted by
10ur
over 2 years ago

Want your dog to bark() while greet()ing?

It is not really a question actually. I tried to find out a way of calling a method from another method and found it! Here is how to do it:
class Dog{
public $numLegs = 4;
public $name;
public function __construct($name){
$this->name = $name;
}
public function bark(){
return "woof!";
}
public function greet(){
return "hello,".$this->bark()." my name is ".$this->name." ".$this->bark();
}
}

You chould simply put "woof" instead of calling bark(), but it might be useful for your other projects ^.^