chaining methods what needs to be changed in class
<p>I have the following class and I want to implement chaining methods. I am kinda teaching my ownself so I thought it would be neat to test chaining. However that didnt work. What would I need to do that</p>

<pre><code>echo $animal-&gt;name.'  says'.$animal-&gt;speak()-&gt;likes()."&lt;br /&gt;"; 
</code></pre>

<p>here is my complete code </p>

<pre><code>&lt;?php 
class Animal{

    var $name;
    function __construct(){

        $this-&gt;name = $name;

    }

}


class Dog extends Animal{


    public function speak(){

        return "Woof Woof";


    }
    public function likes(){

        return "steaks";


    }

}

class Cat extends Animal{

    public function speak(){

        return "Meow Meow";

    }

    public function likes(){

        return "tuna";

    }

}

$animals = array(new Dog('skippy'), new Cat('snowball'));
foreach($animals as  $animal){
    echo $animal-&gt;name.'  says'.$animal-&gt;speak()-&gt;likes()."&lt;br /&gt;"; 


}
?&gt;
</code></pre>
