Re: PHP Objects and cyclical references - HELP

From: Date: Sat, 10 May 2003 04:03:57 +0000
Subject: Re: PHP Objects and cyclical references - HELP
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-1413@lists.php.net to get a copy of this message
Hi, This list is intended for the development of php runtime, not for such user questions. Please ask your questions at php-general@lists.php.net. Thanks. Moriyoshi hint: use "&" "Paul Lunceford" <luncep@comcast.net> wrote: > 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 (#1413) next »