Reputation: 1614
I have a tiny issues.
I have 3 classes:
Class Animal {
public $dog;
function __construct() {
$this->dog = new Dog();
}
}
Class Dog {
public $scream;
function __construct() {
$this->scream = new Scream();
}
}
Class Scream {
public $scream;
function __construct() {
}
public haaa(){
return 'hello World';
}
}
I'm trying to get haaa()
function.. with
$animal = new Animal();
$animal->haaa();
If the function haaa()
is into the Dog
class.. it works fine.. Is it possible that we have a limit of deep encapsulation?
Thank you!
Upvotes: 0
Views: 74
Reputation: 37431
Based on your example it would be:
$animal->dog->haaa();
However, it might be best to change the design so that Dog extends Animal
:
class Dog extends Animal {
public function scream(){
// do stuff
}
}
$dog = new Dog();
$dog->scream();
That's more semantic, since dogs belong to the animal "kingdom".
Upvotes: 4