Let's say I have the following class:
class animal{
private $animal;
private $som;
function gato(){
$this->animal = 'gato';
return $this;
}
function cachorro(){
$this->animal = 'cachorro';
return $this;
}
function mia()
{
$this->som = 'miau';
return $this;
}
function late()
{
$this->som = 'au au';
return $this;
}
}
From this point I could chain the methods as follows
$animal = new animal();
$animal->gato()->mia();
$animal->cachorro()->late();
Or else:
$animal = new animal();
$animal->gato()->late();
$animal->cachorro()->mia();
As you can see above, by the code I said "my dog", but I would like certain methods to be inaccessible, ie if I call the "cat" method I would like only the "mia" method to be accessible to chain.
I know that if I divide the methods into distinct classes it is easier to do this, even more organized, but I want to know if it is possible to perform such a task within the same class.