You are here: Classes, Constructors, References and Recursion « PHP « IT news, forums, messages
Classes, Constructors, References and Recursion

Posted by Evert | Rooftop Solutions on 04/20/05 20:51

Hi,

I have this piece of code:

class test1 {

var
$data = 'hi',
$node = false;


function test1() {

$this->node =& new test2($this);

}

}



class test2 {

var
$data = 'yoyo',
$root = false;

function test2(&$root) {

$this->root =& $root;

}


}


$test =& new test1();
echo('<pre>');
print_r($test);
echo('</pre>');

And it outputs:

test1 Object
(
[data] => hi
[node] => test2 Object
(
[data] => yoyo
[root] => test1 Object
(
[data] => hi
[node] => *RECURSION*
)

)

)
while it should output:

test1 Object
(
[data] => hi
[node] => test2 Object
(
[data] => yoyo
[root] => *RECURSION*

)

)


I know there are some difficulties using references in constructors, but
I think this should be right..
I'm using PHP/4.3.11. Can anyone tell me what is wrong with this code or
why PHP behaves this way?

regards,
Evert

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация