references
| From: | Vladislav Shulgin | Date: | Thu, 13 May 2004 19:10:49 +0000 |
| Subject: | references | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-186148@lists.php.net to get a copy of this message | ||
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