PHP Objects and cyclical references - HELP

From: Date: Fri, 09 May 2003 14:59:55 +0000
Subject: PHP Objects and cyclical references - HELP
Groups: php.internals 
Request: Send a blank email to internals+get-1410@lists.php.net to get a copy of this message
I am just getting to know PHP and am a big proponent of object structures. I am trying to use PHP classes that get instanciated on the fly from data within MySQL. My problem is this. If I have a Department class that has as a variable Employees and an Employee class (along with an Employees class with a list variable for getting sets of employees) that has a variable Division (to navigate back and forth). I seem to have problems getting the objects to point to one another. PHP does not seem to like cyclical references and makes copies of my objects. So if I have the following function in my Division class: function getEmployees() { $myEmployees = new Employees($this->DivisionID); forEach ($myEmployees->list as $employee) { $employee->Division = $this; $this->Employees[$employee->EmployeeNumber] = $employee; } } the reference of $employee->Division becomes only a copy of the $this object. This is a problem because the first employee to go through the loop when asked other employees within his division sees none, thinking himself the only employee of the division. Does anyone know the solution? Please email response to paul.luceford@enterworks.com. Thanks.

« previous php.internals (#1410) next »