Answer the question
In order to leave comments, you need to log in
How to correctly initialize an object in an object?
Guys, tell me. It is necessary in the first class, to assign to the $this->a property an array from the outer class (Test2).
class Test{
protected $a = array();
public function __construct(){
$tmp = new Test2();
$this->a = $tmp->get();
}
}
class Test2{
private $data = array();
public function __construct(){
$this->data = range(1,100);
}
public function get(){
return $this->data;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question