Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1410 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20096 invoked by uid 1007); 9 May 2003 15:02:04 -0000 Message-ID: <20030509150204.20095.qmail@pb1.pair.com> To: internals@lists.php.net Date: Fri, 9 May 2003 10:59:55 -0400 Lines: 27 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Posted-By: 68.48.192.134 Subject: PHP Objects and cyclical references - HELP From: luncep@comcast.net ("Paul Lunceford") 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.