Hi all,
I found a solution to my problem:
class CPatient{
var $m_Age;
var $m_Skeleton;
function CPatient() {
$this->m_Skeleton = new CSkeleton($this);
}
}
class CSkeleton{
var $m_BoneDensity;
var $m_Parent;
function CSkeleton(&$Parent) {
// Set pointer to parent
$this->m_Parent = &$Parent;
}
function GetDensity() {
// Bone density is calc based on
// patient's age
$this->m_BoneDensity = $this->m_Parent->m_Age * whatever.
}
}
At first, this code did not work when I created my patient:
$Patient = new CPatient();
$Patient->m_Age = 22;
// This fetched a NULL age, thus making
// the calc wrong
$Patient->m_Skeleton->GetDensity();
However, changing the instantiation of the parent worked like a charm:
// Note reference to $Parent
$Patient =& new CPatient();
$Patient->m_Age = 22;
// Calc works. Age fetched
$Patient->m_Skeleton->GetDensity();
Hope this helps anyone with this problem. BTW, I found the solution at Zend, under their OOP for PHP section.
Cheers,
Jason