Is it possible for a PHP class to store an object of the same class? Or is there some way to implement this behaviour? In c++ it is possible with pointers but there are no pointers in PHP.
Yes, it is possible. Check this example :
class Obj {
private $obj ;
public function setObject($obj) {
$this->obj = $obj ;
}
public function createAnother() {
return new Obj();
}
public function createOwnObject() {
$this->obj = new Obj();
}
}
$obj1 = new Obj ;
$obj2 = new Obj ;
$obj2->setObject($obj1) ;
$obj3 = $obj2->createAnother() ;