Hi!

I found that when I try to call class method "addchild" from reference of
object - php change not original object. New copy of object will created.

Very strange....

Example:
<?
class pages {
 var $childs;
 var $absnum;
 function pages($absnum) {
  $this->absnum = $absnum;
 }
 function addchild(&$node) {
  if (!is_array($this->childs))
   $this->childs = array();
  $this->childs[$node->absnum] = $node;
 }
}

$allpages = new pages(0);
$allrows = array();
$allrows[0] = &$allpages;

$allrows[2] = &new pages(2);
$allrows[0]->addchild($allrows[2]);

$allrows[3] = &new pages(3);
$allrows[0]->addchild($allrows[3]);

$allrows[4] = &new pages(4);
$allrows[3]->addchild($allrows[4]);

// This is data of object $allrows[3]
echo '<pre>';
print_r($allrows[3]);

echo '</pre>';

// But in global array element $allrows[3] have another value
echo '<pre>';
print_r($allpages);
echo '</pre>';
?>

Any ideas?

Thanks

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

Reply via email to