Title: RE: [PHP] Reference problem

I wrote an xml parsing class, and xml tag class, that might help you there

see the attachment

-----Original Message-----
From: John English [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 01, 2002 12:35 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP] Reference problem


I'm trying to build a tree of objects using PHP4, but I'm getting
tangled in reference problems. Some test code that illustrates the
problem:

  class X {
    var $parent;
    var $ident;
    var $kids;
    function X (&$parent,$number) {
      $this->parent = $parent;
      $this->ident  = $number;
      $this->kids   = array();
    }
  }

  $root = new X($here,1);
  $here =& $root;
  for ($i = 2; $i < 5; $i++) {
    $elem = new X($here,$i);
    $here->kids[] = $elem;
    $here =& $elem;      #--- ???
  }
  print_r($root);

I'm hoping for a structure where each node has a link to the parent
node and an array of child nodes. Instead I get a recursive set of
trees; removing the & on the line marked "???" means I get an empty
kids array in the first child node. I've been sprinkling &'s around
(and unsprinkling them ;-) and my head is starting to hurt.

Can anyone tell me what I'm doing wrong here?

TIA,

-----------------------------------------------------------------
 John English              | mailto:[EMAIL PROTECTED]
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Reply via email to