I have a CLI script written in PHP. In this script I have one instance of mainClass which contains a lot of instances of objects of other types which are stored in PHP arrays. How do I destroy $mainObject and all of the objects it contains?
EXAMPLE CODE:
class mainClass
{
private $_array1 = array();
private $_array2 = array();
private $_array3 = array();
public function __construct($data)
{
foreach ($data['a1'] as $val) {
$this->_array1[] = new Object1($val);
}
foreach ($data['a2'] as $val) {
$this->_array2[] = new Object2($val);
}
foreach ($data['a3'] as $val) {
$this->_array3[] = new Object3($val);
}
}
}
$mainObject = new mainClass($data);
function someFunction(mainClass $mainObject)
{
unset($mainObject);
}
- Does unset($mainObject) will destroy it and all objects it contains?
- Do I have to destroy every object separately?
- Should I use destructor of the mainClass to destroy objects (call theirs destructors) that $mainObject contains?