hello vincent,
i thought the same, but i can't understand, why then $g_test isn't undefined (the value doesn't exist), but contains the old value. that sounds ilogical.
you asked me, what i'm trying to archive:
i want to convert a xml-document into a tree of xml-elements, that store their childs in an array and a reference to their parent.
i wrote a short portion of executable code, that shows my problem:
<?
class CTreeElement
{
var $m_szName;
var $m_arSubElems;
var $m_parent;
// constructor
function CTreeElement($szName, &$parent)
{
$this->m_szName = $szName;
$this->m_arSubElems = array();
$this->m_parent = &$parent;
}
function addSubElem(&$sub)
{
array_push($this->m_arSubElems, &$sub);
}
}
$dummy = 0;
$g_curElem = &new CTreeElement('root', $dummy);
$g_newElem = null;
function addElem($name)
{
global $g_curElem;
global $g_newElem;
$g_newElem = &new CTreeElement($name, $g_curElem);
$g_curElem->addSubElem($g_newElem);
$g_curElem = &$g_newElem;
}
addElem('elem1');
print('cur elem: ' . $g_curElem->m_szName . ', array count: ' . count($g_curElem->m_arSubElems) . '<br>');
print('parent: ' . $g_curElem->m_parent->m_szName . ', array count: ' . count($g_curElem->m_parent->m_arSubElems) . '<br>');
?>
i declared $g_newElem as global, to prevent an undefined status of $g_curElem.
i expect the following output:
cur elem: elem1, array count 0
parent: root, array count 1
but the result is:
cur elem: root, array count: 1
parent: , array count: 0
this means, that $g_curElem wasn't assigned in addElem(). or more exactly, that it's only assigned to the new object inside of addElem().
i don't understand nothing and start desperating ...
matze