Am I allowed to do them? Is it really naughty?
I have something similar to this:
php code:
GedcomElement extends DOMElement {
private $obj;
public function __construct($name){
switch($name){
case "INDI":
$this->obj = new Individual($this);
break;
case "FAM":
$this->obj = new Family($this);
break;
}
}
public function __destruct(){
$this->obj = null;
}
}
Basically I'm overriding DOMElement with a new version of the element which stores an object inside it with a reference to itself.
Is this really bad practice?
I'm trying to clean up at the end with the destruct method.
Basically, I have a list of 'individuals' (with lots of attributes) and a list of 'families' (with lots of attributes). individuals also store id's of two different families and familes also store id's of multiple individuals.
Example XML file:
xml code:
<?xml version="1.0"?>
<GEDCOM>
<INDIVIDUALS>
<INDI id="@I1@">
<NAME text="Bob /Cox/"/>
<SEX text="M"/>
<FAMS text="@F1@"/>
<CHAN>
<DATE text="11 FEB 2006"/>
</CHAN>
</INDI>
<INDI id="@I2@">
<NAME text="Joann /Para/"/>
<SEX text="F"/>
<FAMS text="@F1@"/>
<CHAN>
<DATE text="11 FEB 2006"/>
</CHAN>
</INDI>
<INDI id="@I3@">
<NAME text="Bobby Jo /Cox/"/>
<SEX text="M"/>
<FAMC text="@F1@"/>
<CHAN>
<DATE text="11 FEB 2006"/>
</CHAN>
</INDI>
</INDIVIDUALS>
<FAMILIES>
<FAM id="@F1@">
<HUSB text="@I1@"/>
<WIFE text="@I2@"/>
<MARR/>
<CHIL text="@I3@"/>
</FAM>
</FAMILIES>
</GEDCOM>
I can then do something like this:
php code:
$dom->getIndividualById("@F1@")->GetWife();
Where getIndividualById will return the $obj in the relevant node, and GetWife() will use XPath on the owner document to find the correct element then return the $obj within that element.
So, is it really really bad for objects to store references to themselves in objects contained within themselves?
EDITED: 28 Aug 2008 11:28 by MIKEE