A
A
Alexander Karpov2016-04-22 11:22:56
PHP
Alexander Karpov, 2016-04-22 11:22:56

When might it be necessary to store a class object inside itself?

The question is stupid, but I could not help but ask, it was very necessary. When might this be needed? Thanks for answers!

class MyClass
{
   public $class;
   public function __construct()
   {
       $this->class=new MyClass;
   }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dev400, 2016-04-22
@Inkognitoss

When the constructor takes some arguments, they do so. Recursion.

S
Sergey, 2016-04-22
Protko @Fesor

Only when describing tree-like data structures. But not in the constructor, because in this case we get a recursive call to the object's constructor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question